*
* Example 11.4 from p 231
* Feasible GLS for heteroscedasticity
*
open data incexp.txt
data(format=prn,org=columns) 1 100 mdr acc age income avgexp ownrent selfempl
*
set incomesq = income**2
set posexp   = avgexp>0
*
* Restrict all estimates to the observations with positive expenditures
*
smpl(series=posexp)
*
* Linear regression with heteroscedasticity robust standard errors
*
linreg(robusterrors) avgexp / resids
# constant age ownrent income incomesq
*
* Variance assumed proportional to income
*
linreg(spread=income) avgexp
# constant age ownrent income incomesq
*
* Variance assumed proportional to income squared
*
linreg(spread=incomesq) avgexp
# constant age ownrent income incomesq
*
* This is a FGLS (feasible GLS) procedure. The variance
* is assumed to be proportional to exp(a0+a1*income+a2*income**2)
* where a0, a1 and a2 are unknown. The parameters are estimated
* by a regression of log(resids**2) on 1, income and income**2.
* The spread series is the exp of the fitted values from that
* regression.
*
set logusq = log(resids**2)
linreg logusq
# constant income incomesq
prj logvar
linreg(spread=exp(logvar)) avgexp
# constant age ownrent income incomesq

