FOCUS AREAS

SAS/ETS Examples

A Simple Regression Model with Correction of Heteroscedasticity


Contents | Back to Example

SAS Program

/* Regression Model with Correction of Heteroskedasticity */

data hetero1;
  input state exp inc;
   inc=inc/10000;
   inc2=inc**2;
  if exp = . then delete;
  datalines;
1     275 6247
2     275 6183
3     531 8914
4     316 7505
5     304 6813
6     431 7873
7     316 6640
8     427 8063
9     259 5736
10    294 7391
11    423 8818
12    335 6607
13    320 6951
14    342 7526
15    268 6489
16    353 6541
17    320 6456
18    821 10851
19    387 8850
20    424 8604
21    265 6700
22    437 8745
23    355 8001
24    327 6333
25    466 8442
26    274 7342
27    359 9032
28    388 6505
29    311 7478
30    397 7839
31    315 6242
32    315 7697
33    356 7624
34     .  7597
35    339 7374
36    452 8001
37    428 10022
38    403 8380
39    345 7696
40    260  6615
41    427  8306
42    477  7847
43    433  7051
44    279  7277
45    447  8267
46    322  7812
47    412  7733
48    321  6841
49    417  6622
50    415  8450
51    500  9096
;

/* Ordinary Least Squares */

title 'Ordinary Least Squares';

proc model data=hetero1;
  parms a1 b1 b2;
  exp = a1 + b1 * inc + b2 * inc2;
  fit exp / white pagan=(1 inc inc2)
  out=resid1 outresid;
run;
quit;

proc gplot data=resid1;
   plot exp*inc / vref=0 cvref=red;
   symbol c=blue value=star;
   title1 'Residual vs. Per Capita Income';
   title2 'Ordinary Least Squares';
run;
quit;

/* Weighted Least Squares */

title 'Weighted Least Squares';
title2;

proc model data=hetero1;
  parms a1 b1 b2;
  inc2_inv = 1/inc2;
  exp = a1 + b1 * inc + b2 * inc2;
  fit exp / white pagan=(1 inc inc2);
  weight inc2_inv;
run;
quit;