SAS CODE FOR HETEROSCEDASTICITY
libname w
'c:\Documents and Settings\ApecUser\My Documents\Teaching\ApEc5031\Wooldridge Datasets\';
proc reg data=w.hprice1;
model lprice=lassess llotsize lsqrft bdrms;
run;
data hprice1;
set w.hprice1;
diff=lprice-lassess;
run;
proc reg data=hprice1;
model diff=;
run;
proc reg data=w.hprice1;
model lprice=lassess llotsize lsqrft bdrms;
test lassess=1, llotsize=0, lsqrft=0, bdrms=0;
run;
proc reg data=w.hprice1;
model lprice=lassess llotsize lsqrft bdrms/acov;
test lassess=1, llotsize=0, lsqrft=0, bdrms=0;
run;
proc reg data=w.hprice1;
model lprice=lsqrft;
output out=resid
p=lprhat
r=uhat;
run;
proc reg data=resid;
model llotsize=lsqrft;
output out=resid1
p=lsqfthat
r=r1hat;
run;
proc reg data=resid1;
model bdrms=lsqrft;
output out=resid2
p=bdrmhat
r=r2hat;
run;
data final;
set resid2;
r1u=r1hat*uhat;
r2u=r2hat*uhat;
one=1;
run;
proc reg data=final;
model one=r1u r2u/noint;
run;
proc reg data=w.hprice1;
model lprice=llotsize lsqrft bdrms;
output out=resid
p=lprhat
r=uhat;
run;
data resid2;
set resid;
u2=uhat*uhat;
run;
proc reg data=resid2;
model u2=llotsize lsqrft bdrms;
run;
proc reg data=w.hprice1;
model lprice=llotsize lsqrft bdrms;
output out=resid
p=lprhat
r=uhat;
run;
data resid2;
set resid;
u2=uhat*uhat;
lprhat2=lprhat*lprhat;
lot2=llotsize*llotsize;
sq2=lsqrft*lsqrft;
bd2=bdrms*bdrms;
lot_sq=llotsize*lsqrft;
bd_sq=bdrms*lsqrft;
lot_bd=llotsize*bdrms;
run;
proc reg data=resid2;
model u2=llotsize lsqrft bdrms lot2 sq2 bd2 lot_sq bd_sq lot_bd;
run;
proc reg data=resid2;
model u2=lprhat lprhat2;
run;
proc reg data=w.hprice1;
model lprice=llotsize lsqrft bdrms/spec;
run;
proc reg data=w.saving;
title "OLS run";
model sav=inc size educ age black;
output out=resid
p=lprhat
r=uhat;
run;
data saving;
set w.saving;
adjsav=sav/sqrt(inc);
adjint=1/sqrt(inc);
adjinc=inc/sqrt(inc);
adjsize=size/sqrt(inc);
adjeduc=educ/sqrt(inc);
adjage=age/sqrt(inc);
adjblack=black/sqrt(inc);
run;
proc reg data=saving;
title "Manual WLS";
model adjsav=adjint adjinc adjsize adjeduc adjage adjblack/noint;
run;
data saving;
set w.saving;
wght=1/inc;
run;
proc reg data=saving;
title "Automatic WLS";
model sav=inc size educ age black;
weight wght;
run;
proc reg data=w.saving;
title "White's errors without weights";
model sav=inc size educ age black/acov;
run;
proc reg data=saving;
title "White's errors with weights";
model sav=inc size educ age black/acov;
weight wght;
run;
proc reg data=w.saving;
title "Saving OLS residuals";
model sav=inc size educ age black;
output out=resid
r=uhat
p=yhat;
run;
data resid2;
set resid;
logu2=log(uhat*uhat);
yhat2=yhat*yhat;
run;
proc reg data=resid2;
title "Calculating ghat";
model logu2=inc size educ age black;
output out=fitted
p=ghat;
run;
data fitted2;
set fitted;
hhat=exp(ghat);
wght=1/hhat;
run;
proc reg data=fitted2;
title "feasible GLS";
model sav=inc size educ age black;
weight wght;
run;
proc reg data=resid2;
title "Calculating ghat=f(yhat, yhat2)";
model logu2=yhat yhat2;
output out=fitted
p=ghat;
run;
data fitted2;
set fitted;
hhat=exp(ghat);
wght=1/hhat;
run;
proc reg data=fitted2;
title "feasible GLS with ghat=f(yhat,yhat2)";
model sav=inc size educ age black;
weight wght;
run;
site from
http://blog.sina.com.cn/s/blog_58ea0d1f0101jc2c.html