Lecture 8: Heteroskedasticity: Causes Consequences Detection Fixes
Lecture 8: Heteroskedasticity: Causes Consequences Detection Fixes
Causes
Consequences
Detection
Fixes
Assumption MLR5:
Homoskedasticity
var(u | x1 , x2 ,..., x j ) 2
------------------------------------------------------------------------------
hsgpa | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
male | -.1574331 .0122943 -12.81 0.000 -.181534 -.1333322
hisp | -.0600072 .0174325 -3.44 0.001 -.0941806 -.0258337
black | -.1402889 .0152967 -9.17 0.000 -.1702753 -.1103024
other | -.0282229 .0186507 -1.51 0.130 -.0647844 .0083386
agedol | -.0105066 .0048056 -2.19 0.029 -.0199273 -.001086
dfreq1 | -.0002774 .0004785 -0.58 0.562 -.0012153 .0006606
schattach | .0216439 .0032003 6.76 0.000 .0153702 .0279176
msgpa | .4091544 .0081747 50.05 0.000 .3931294 .4251795
r_mk | .131964 .0077274 17.08 0.000 .1168156 .1471123
income1 | 1.21e-06 1.60e-07 7.55 0.000 8.96e-07 1.52e-06
antipeer | -.0167256 .0041675 -4.01 0.000 -.0248953 -.0085559
_cons | 1.648401 .0740153 22.27 0.000 1.503307 1.793495
------------------------------------------------------------------------------
Let’s see if the regression from the
midterm has heteroskedasticity . . .
. predict gpahat
2
(option xb assumed; fitted values)
. predict residual, r
. scatter residual gpahat, msize(tiny)
or . . .
1
. rvfplot, msize(tiny)
Residuals
0
-1
-2
1 2 3 4
Fitted values
Let’s see if the regression from the
midterm has heteroskedasticity . . .
. predict gpahat
2
(option xb assumed; fitted values)
. predict residual, r
. scatter residual gpahat, msize(tiny)
max(uˆ ) 4 yˆ
or . . .
1
. rvfplot, msize(tiny)
Residuals
0
-1
-2
1 2 3 4
Fitted values
Let’s see if the regression from the
2010 midterm has heteroskedasticity
2
. scatter residual msgpa, msize(tiny) jitter(5) same issue
or . . .
. rvpplot msgpa, msize(tiny) jitter(5)
1 ↓
Residuals
0
-1
-2
0 1 2 3 4
msgpa
Other useful plots for detecting
heteroskedasticity
twoway (scatter resid fitted) (lowess resid fitted)
Same as rvfplot, with an added smoothed line for
residuals – should be around zero.
You have to create the “fitted” and “resid” variables
twoway (scatter resid var1) (lowess
resid var1)
Same as rvpplot var1, with smoothed line added.
Formal tests for heteroskedasticity
regression in step 2.
4) LM is distributed chi-square with k degrees
of freedom.
5) Reject homoskedasticity assumption if p-
value is below chosen alpha level.
Formal test for heteroskedasticity:
“Breusch-Pagan” test, example
After high school gpa regression (not shown):
. predict resid, r
. gen resid2=resid*resid
. reg resid2 male hisp black other agedol dfreq1 schattach msgpa r_mk income1 antipeer
Source | SS df MS Number of obs = 6574
-------------+------------------------------ F( 11, 6562) = 9.31
Model | 12.5590862 11 1.14173511 Prob > F = 0.0000
Residual | 804.880421 6562 .12265779 R-squared = 0.0154
-------------+------------------------------ Adj R-squared = 0.0137
Total | 817.439507 6573 .124363229 Root MSE = .35023
------------------------------------------------------------------------------
resid2 | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
male | -.0017499 .008919 -0.20 0.844 -.019234 .0157342
hisp | -.0086275 .0126465 -0.68 0.495 -.0334188 .0161637
black | -.0201997 .011097 -1.82 0.069 -.0419535 .0015541
other | .0011108 .0135302 0.08 0.935 -.0254129 .0276344
agedol | -.0063838 .0034863 -1.83 0.067 -.013218 .0004504
dfreq1 | .000406 .0003471 1.17 0.242 -.0002745 .0010864
schattach | -.0018126 .0023217 -0.78 0.435 -.0063638 .0027387
msgpa | -.0294402 .0059304 -4.96 0.000 -.0410656 -.0178147
r_mk | -.0224189 .0056059 -4.00 0.000 -.0334083 -.0114295
income1 | -1.60e-07 1.16e-07 -1.38 0.169 -3.88e-07 6.78e-08
antipeer | .0050848 .0030233 1.68 0.093 -.0008419 .0110116
_cons | .4204352 .0536947 7.83 0.000 .3151762 .5256943
------------------------------------------------------------------------------
Formal test for heteroskedasticity:
Breusch-Pagan test, example
. di "LM=",e(N)*e(r2)
LM= 101.0025
. di chi2tail(11,101.0025)
1.130e-16
estat hettest
Square residuals and divide by mean so that new
variable mean is 1
Regress this variable on yhat
Model sum of squares / 2 ~ 1
2
Other versions of the Breusch-Pagan
test
. estat hettest, rhs
chi2(11) = 116.03
Prob > chi2 = 0.0000
. estat hettest
chi2(1) = 93.56
Prob > chi2 = 0.0000
chi2(3) = 3.26
Prob > chi2 = 0.3532
Tests for heteroskedasticity: White’s test,
complicated version
------------------------------------------------------------------------------
r2 | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
gpahat | .0454353 .0816119 0.56 0.578 -.1145505 .2054211
gpahat2 | -.023728 .0152931 -1.55 0.121 -.0537075 .0062515
_cons | .2866681 .1067058 2.69 0.007 .0774901 .4958461
------------------------------------------------------------------------------
. di "LM=",e(r2)*e(N)
LM= 83.81793
. di chi2tail(2,83.81893)
6.294e-19
. whitetst
i
( x x ) i
2 2
2 the ideal
var( ˆ )
1
i 1
2
, if i
i
2 2
SSTx SSTx
n
i
( x x ) uˆi
2 2
----------------------------------
Variable | ols robust
-------------+--------------------
male | -.157 -.157 parameter estimates, unchanged
| .0123 .0124 standard errors
| -12.8 -12.7 T-statistics
hisp | -.06 -.06
| .0174 .0173
| -3.44 -3.46
black | -.14 -.14
| .0153 .0157
| -9.17 -8.91
other | -.0282 -.0282
| .0187 .0186
| -1.51 -1.52
agedol | -.0105 -.0105
| .0048 .0048
| -2.19 -2.19
Heteroskedasticity-robust inference,
example cont.
High school GPA models, cont. High school GPA models, cont.
---------------------------------- ----------------------------------
Variable | ols robust Variable | ols robust
-------------+-------------------- -------------+--------------------
dfreq1 | -.00028 -.00028 antipeer | -.0167 -.0167
| 4.8e-04 5.4e-04 | .0042 .0043
| -.58 -.509 | -4.01 -3.9
schattach | .0216 .0216 _cons | 1.65 1.65
| .0032 .0034 | .074 .0752
| 6.76 6.4 | 22.3 21.9
msgpa | .409 .409 -------------+--------------------
| .0082 .0088 r2 | .506 .506
| 50.1 46.3 rmse | .483 .483
r_mk | .132 .132 ----------------------------------
| .0077 .0079 legend: b/se/t
| 17.1 16.6
income1 | 1.2e-06 1.2e-06 .
| 1.6e-07 1.5e-07
| 7.55 7.87
.
Despite solid evidence for heteroskedasticity in this
model, very little changes when heteroskedasticity-
robust standard errors are calculated.
Why did the estimates change so little?
Heteroskedasticity-robust inference of
Lagrange multiplier
The book outlines a very involved set of steps to obtain a Lagrange
Multiplier test that is robust to heteroskedasticity.
We’ll go through these steps, testing whether hisp black and other are jointly
significant
1) Obtain residuals from restricted model
. quietly reg hsgpa male agedol dfreq1 schattach msgpa r_mk income1 antipeer
. predict residuals
2) Regress each excluded independent variable on the included independent
variables, generate residuals
. quietly reg hisp male agedol dfreq1 schattach msgpa r_mk income1
antipeer
. predict rhisp, r
. quietly reg black male agedol dfreq1 schattach msgpa r_mk income1
antipeer
. predict rblack, r
. quietly reg other male agedol dfreq1 schattach msgpa r_mk income1
antipeer
. predict rother, r
3) Generate products of residuals from restricted model and residuals from
each auxiliary regression
. gen phisp=residuals*rhisp
. gen pblack=residuals*rblack
. gen pother=residuals*rother
Heteroskedasticity-robust inference of
Lagrange multiplier
4) Regress 1 on these three products without a constant, N-SSR~χ2 with q
degrees of freedom
. gen one=1
. reg one phisp pblack pother, noc
. di e(N)-e(rss)
79.289801
. di chi2tail(3,79.289801)
4.359e-17
Based on this test, we’d reject the null that hisp black and other are jointly
equal to zero.
Another much easier option for heteroskedasticity-robust tests of joint
restrictions is to run F-tests after a regression model with robust standard
errors
. quietly reg hsgpa male hisp black other agedol dfreq1
schattach msgpa r_mk income1 antipeer, robust
. test hisp black other
( 1) hisp = 0
( 2) black = 0
( 3) other = 0
F( 3, 6562) = 27.01
Prob > F = 0.0000
Obtaining standard errors with
bootstrapping
Bootstrapping (Wooldredge, pp. 223-4)
In general, if the distribution of some statistic is unknown,
bootstrapping can yield confidence intervals free of
distributional assumptions.
It resamples the dataset with replacement and re-
estimates the statistic of interest many times (~1000 is
good).
Conceptually equivalent to drawing many random
samples from the population.
The standard deviation of the statistic of interest from the
replications is the standard error of the statistic in the
original model.
This is incorporated into the regress function in Stata
. reg y x, vce(bs, r(N))
N is the number of replications
Obtaining standard errors with
bootstrapping
Bootstrapping (Wooldredge, pp. 223-4)
If you are using bootstrapping for a paper, before the
bootstrap, use the “set seed N” command where N is
any particular number. Otherwise, you’ll get different
results every time.
You can also bootstrap other statistics with no obvious
distribution, just in case you wanted a confidence interval
for them
. bs e(r2), r(1000): reg Y X
. bs e(rmse), r(1000): reg Y X
. bs r(p50), r(1000): summarize hsgpa, detail
Obtaining standard errors with
bootstrapping
Bootstrapping (Wooldredge, pp. 223-4
After bootstrapping, we can get more information
using the command “estat bootstrap, all”
For each statistic, this reports the following:
“bias” : the mean of the bootstrapped estimates minus
the estimate from our original model.
Normal confidence interval, as reported before
Percentile confidence interval: limits defined by 2.5th
and 97.5th percentiles of the boostrapped estimates
Bias-corrected confidence interval: normal confidence
interval minus bias
Modeling heteroskedasticity, weighted least
squares
Var (u | x) h( x)
2
------------------------------------------------------------------------------
hsgpa_ms | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
con_ms | 1.751627 .0751105 23.32 0.000 1.604386 1.898868
male_ms | -.1602267 .0129001 -12.42 0.000 -.1855151 -.1349384
hisp_ms | -.0377276 .0182012 -2.07 0.038 -.0734079 -.0020472
black_ms | -.1319019 .0157097 -8.40 0.000 -.1626981 -.1011057
other_ms | -.0305844 .0195973 -1.56 0.119 -.0690015 .0078327
agedol_ms | -.0121919 .0050095 -2.43 0.015 -.0220121 -.0023717
dfreq1_ms | -2.45e-07 .0004347 -0.00 1.000 -.0008525 .000852
schattach_ms | .022701 .0032899 6.90 0.000 .0162516 .0291503
msgpa_ms | .377467 .0075196 50.20 0.000 .362726 .3922079
r_mk_ms | .1167528 .0079359 14.71 0.000 .1011959 .1323097
income1_ms | 1.14e-06 1.75e-07 6.50 0.000 7.96e-07 1.48e-06
antipeer_ms | -.0195269 .0042784 -4.56 0.000 -.027914 -.0111397
------------------------------------------------------------------------------
Modeling heteroskedasticity, weighted
least squares
Questions 8 through 10
Next time: