Data food;
input food inc;
wt = 1/inc;
datalines;
52.25 258.3
58.32 343.1
81.79 425
119.9 467.5
125.8 482.9
100.46 487.7
121.51 496.5
100.08 519.4
127.75 543.3
104.94 548.7
107.48 564.6
98.48 588.3
181.21 591.3
122.23 607.3
129.57 611.2
92.84 631
117.92 659.6
82.13 664
182.28 704.2
139.13 704.8
98.14 719.8
123.94 720
126.31 722.3
146.47 722.3
115.98 734.4
207.23 742.5
119.8 747.7
151.33 763.3
169.51 810.2
108.03 818.5
168.9 825.6
227.11 833.3
84.94 834
98.7 918.1
141.06 918.1
215.4 929.6
112.89 951.7
166.25 1014
115.43 1141.3
269.03 1154.6
;
/* Run an ordinary least squares regression of food on inc. */
title 'OLS Estimation of the Consumption Function for Food';
proc reg data=food;
model food = inc;
output out=result p=pred r=resid;
run;
/* Here we print out the residuals to see if heteroskedasticity is present. */
proc print data=result;
run;
/* Here we use the White's Heteroskedasticity Test to test for Heteroskedastity
in the errors of the OLS equation. It is just the overall F-test of the below
test equation. */
data result;
set result;
res2 = resid**2;
inc2 = inc**2;
title 'White Heteroskedastity Test';
proc reg data=result;
model res2 = inc inc2;
/* Here we use weighted least squares assuming "proportionate" heteroskedasticity.
Notice the weight in SAS is defined to be proportional to the reciprocal of the
variance of the errors whereas in EVIEWS the weight is defined to be proportional
to the reciprocal of the standard deviation of the errors. */
title 'WLS Estimation of the Consumption Function for Food';
proc reg data=food;
model food = inc;
weight wt;
run;
/* Here we are going to do WLS by "Brute force." */
data food;
set food;
foodt = food/inc**0.5;
onet = 1/inc**0.5;
inct = inc/inc**0.5;
title 'WLS by Brute Force';
proc reg data=food;
model foodt = onet inct/noint;
run;
/* One can also produce the White's heteroskedasticity consistent standard errors for
the OLS coefficients by using the COVA option in Proc REG. What you have to do is
take the square root of the diagonal elements of the COVA matrix that is given in the
output. */
title 'White Heteroskedasticity Standard Errors for the OLS Estimates';
proc reg data=food;
model food = inc / acov;
run;