The problems of correlated errors (chapter 8)
Code015
option ls=90 ps=75;
title 'Soft Drink Concentrate Sales';
proc reg data=soft;
model y = x / dw; /* D-W statistic */
plot (r. student.)*pred.;
output out=softout p=pred r=resid student=student;
run; quit;
proc gplot data=softout; plot resid*year; run; quit;
proc univariate data=softout normaltest; var student;
qqplot student / normal(mu=0 sigma=1) square; run;
Code016
option ls=90 ps=75;
title 'Toothpaste Market Share';
/* ordinary least squares */
proc reg data=toothpaste;
model y = x / dw;
plot (r. student.)*pred.;
output out=toothpasteout p=pred r=resid student=student;
run; quit;
proc gplot data=toothpasteout; plot resid*period; run; quit;
proc univariate data=toothpasteout normaltest; var student;
qqplot student / normal(mu=0 sigma=1) square; run;
/* Cochrane-Orcutt method */
/* iteration 1 */
data co1; set toothpaste; xstar0=x-.409*lag(x); ystar0=y-.409*lag(y); run;
data co_iter1; set co1 (firstobs=2); run; /* drop the missing values */
proc print data=co_iter1; run;
proc reg data=co_iter1;
model ystar0 = xstar0 / dw;
plot (r. student.)*pred.;
output out=toothpasteout2 p=pred r=resid student=student;
run; quit;
/* equivalent (not rigorously) method to GLS for autoregressive covariance
structure */
proc autoreg data=toothpaste;
model y = x / nlag=1 method=yw;
run;