clear
cd "G:\econometrics\teach\hetero" /*your data path*/
capture log clo
log using "result\heterskedasicity.log", replace
*1) Open your data file
u "data\hprice1.dta", clear
*2) Regress housing price on hou size, and test for heterskedasicity
reg price lotsize sqrft bdrms
whitetst /*You can also try "whitetst, fitted" for e=d+d1yhat+d2yhat^2+v */
bpagan lotsize sqrft bdrms
*3) Regress Log(housing price) on Log(hou size), and test for heterskedasicity
reg lprice llotsize lsqrft bdrms
whitetst /*You can also try "whitetst, fitted" for e=d+d1yhat+d2yhat^2+v */
bpagan llotsize lsqrft bdrms
*4) OLS, with robust sd
reg price lotsize sqrft bdrms, robust
*5)GLS/WLS
bpagan llotsize
reg price lotsize sqrft bdrms [aw = 1/lotsize]
*5)FGLS
reg price lotsize sqrft bdrms /*First, doing OLS, and
we know from 2, this model has heterskedasicity*/
predict e, residual /*get the residual */
gen ln_e2=log(e*e) /*generate log of the square of residual */
reg ln_e2 lotsize sqrft bdrms /*reg residual square on all Xs */
predict ghat, xb /*get predicted value for ln_e2*/
gen =exp(ghat) /*get hhat */
reg price lotsize sqrft bdrms [aw = 1/] /*WLS, using the estimated variance as weight*/
log clo