Google


Wednesday, January 16, 2008

LSTAR

Here is a SAS macro to estimate a logistic STAR(1) model, the first part initialises the parameters by using the OLS coefficients, this avoids the optimisation going off in the wrong direction.

options mprint mlogic;

%macro star(data=,var=,gamma=10,c=);

%if &c= %then %do;
proc summary data=&data;
var &var;
output out=temp;
run;

data _null_;
set temp;
if _stat_='MEAN' then call symput('c',&var);
run;
%end;

data temp2;
set &data;
l&var=lag(&var);
ll&var=lag(l&var);
run;

proc reg data=temp2 outest=temp3;
model &var = l&var ll&var;
run;

data _null_;
set temp3;
call symput('a',intercept);
call symput('b',l&var);
call symput('d',ll&var);
run;

* y_t = phi00+phi01*y_t-1 + (phi10+phi11*y_t-1)*(1/(1+exp(-gamma*(y_{t-1}-c))));
proc nlin data=temp2 maxiter=500 convergence=0.000001;
parms a0=&a b0=&b c0=&d a1=&a b1=&b c1=&d gam=&gamma c=&c;
model &var = a0+b0*l&var +c0*ll&var+ (a1+b1*l&var+c1*ll&var)*(1/(1+exp(-gam*(l&var-c))));
output out=temp4 predicted=&var.f;
quit;
%mend;

* Usage;
%star(data=unemp,var=gmgsx,gamma=30);

No comments: