/*Regression with Autocorrelated Errors AR(1)*/

options ls=80;

data a;

e1=0;

do time=-5 to 100;

e=.7*e1+rannor(1234); /* Var(a)=1 */

y=10+.5*time+e;

if time>0 then output;

e1=e;

end;

run;

 

 

/*To graph we could use Solutions>Analysis>Time Series Viewer*/

 

/*Let's ignore Autocorrelation*/

 ods html ;

Proc autoreg data=a;

 model y=time;

 run;

/*Conclusion: OLS overestimates MSE */

 

 

Proc autoreg data=a;

model y=time/nlag=1 iter; /*The sample size is OK*/

run;

 

data future;

input y time;

datalines;

. 101

. 102

. 103

. 104

. 105

run;

data a1;

update a future;

by time;

run;

 

 

/*A Time Series with AR(1) errors*/

Proc arima data=a1;

identify var=y

crosscor=(time) ;

estimate input=(time) p=(1) printall plot;

forecast lead=12 out=fcast;

run;

 

proc print data=fcast;

run;

 

 ods html close;