Hello, does anyone know a Stata comman to run a Weighted Least Squares estimation in a panel model with both time and individuals fixed effects?
-
Login or Register
- Log in with
sysuse auto, clear
* WLS by hand
reg price length i.foreign //OLS
predict r, r //residual
gen lrsq = ln(r^2) //ln(residual^2)
reg lrsq length //auxiliary regression: assume the variance varies by length
predict lrsqhat
gen h = exp(lrsqhat) //estimate of the variance
reg price length i.foreign [aw=1/h] //WLS
* WLS with -hetregress-
hetregress price length i.foreign, het(length) twostep
. reg price length i.foreign [aw=1/h] //WLS
(sum of wgt is .00007419812346)
Source | SS df MS Number of obs = 74
-------------+---------------------------------- F(2, 71) = 17.20
Model | 94395245.9 2 47197623 Prob > F = 0.0000
Residual | 194866917 71 2744604.46 R-squared = 0.3263
-------------+---------------------------------- Adj R-squared = 0.3074
Total | 289262163 73 3962495.38 Root MSE = 1656.7
------------------------------------------------------------------------------
price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
length | 66.70549 11.67666 5.71 0.000 43.42289 89.98809
|
foreign |
Foreign | 1580.511 428.8698 3.69 0.000 725.3689 2435.653
_cons | -6934.138 2085.765 -3.32 0.001 -11093.03 -2775.241
------------------------------------------------------------------------------
.
. * WLS with -hetregress-
. hetregress price length i.foreign, het(length) twostep
Heteroskedastic linear regression Number of obs = 74
Two-step GLS estimation
Wald chi2(2) = 34.39
Prob > chi2 = 0.0000
------------------------------------------------------------------------------
price | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
price |
length | 66.70549 11.67666 5.71 0.000 43.81966 89.59132
|
foreign |
Foreign | 1580.511 428.8698 3.69 0.000 739.9416 2421.08
_cons | -6934.137 2085.765 -3.32 0.001 -11022.16 -2846.113
-------------+----------------------------------------------------------------
lnsigma2 |
length | .0448232 .0116768 3.84 0.000 .0219371 .0677094
_cons | 7.122623 2.209595 3.22 0.001 2.791897 11.45335
------------------------------------------------------------------------------
Wald test of lnsigma2=0: chi2(1) = 14.74 Prob > chi2 = 0.0001
reg price length i.foreign, vce(robust)
* Identical results
xtreg y x, fe vce(cluster panelid)
xtreg y x, fe vce(robust)
Comment