MACRO getmacro(name,where/?(data/ndata)/)
attach("where")
if(dataset("?(mac.)name")==3)?(mac.)name_?(mac.)name      #copy to work
attach("sdata")
save(?(mac.)name)     #put on database - dies if missing
rm(?(mac.)name)          #remove from work
END


MACRO cp(x,y,wt,int,names)
x.x_x; y.y_y      #make sure args evaluated only once
t.t_leaps(x.x,y.y,?(wt)=wt,?(int)=int,?(names)=names)
plot(t.t$size,t.t$cp,type="n",ylab="cp value",
	xlab="number of variables",
	xlim=range(0,t.t$size+1),log=?("y"))
text(t.t$size,t.t$cp,t.t$label)
lines(seq(max(t.t$size)+1))
"identify the regressions you want to see"
for(j.j in identify(t.t$size,t.t$cp,plot=F))
       regress(x.x[,t.t$which[j.j,]],y.y,?(wt)=wt,?(int)=int,?(names)=names)
END



MACRO dbrm(print=/T/)
attach(work="sdata")      #get database as work file
if(all(dataset(c(?LOOP("$%1",$*)))))
	rm($*,?(print)=print) else 
	"missing data sets - none removed"
attach(work="swork")
END



MACRO sabl(x,power,main)
x.x_x      #evaluate arg only once
?IFELSE(power,,
	p.p_?(power)(x.x)$p; x.x_tstr(x.x,p.p),
	)
?IFELSE(main,,
	m.m_"seasonal decomposition of x"
	if(p.p!=0) m.m_encode(m.m,"; transformed to",p.p,"?(power)"),
	m.m_main)
x.s_sabl(x.x)
tsplot(x.x,x.s$t,x.s$t+x.s$s,type="pll",
?(main)=m.m,
xlab="lines show trend and trend+seasonal")
tsplot(x.s$i,type="h",ylab="irregular",
?(main)=m.m)
monthplot(x.s$s,?(main)=m.m)
ptvar(x.s$s,?(main)=m.m)
ptmrange(x.s,?(main)=m.m)
ptmos(x.s$i,?(main)=m.m)
END



MACRO reg(y,int=,names=)
n.n_?IFELSE(names,,c(?LOOP("$%1",$*)),names)
x.x_cbind($*)
r.r_regress(x.x,y,?(int)=int,?(names)=n.n)
?adjvars(x.x,y,r.r,?(int)=int,?(names)=n.n,$*)	#send on any keyword args not already used
END
