这是greene书上的例子
use "d:\data\dta\greena\table51-greene.dta", clear
rename x1 age
rename x2 income
rename x3 exp
rename x4 ownrent
rename x5 selfemp
generate incomesq = income^2
drop if exp==0
*save chapter12hetero,replace
regress exp age ownrent income incomesq
rvpplot income, xlab(0 2 to 12) xline(2 4 6 8 10) ylab(-500 0 to 2000) yline(0 500 1000 1500)
regress exp age ownrent income incomesq, robust
matrix d = vecdiag(e(V))
matrix v = cholesky(diag(d))
matrix s = sqrt((72-5)/72)*vecdiag(v)
matrix list s
regress exp age ownrent income incomesq, hc2
whitetst
hettest
bpagan income incomesq
wls0 exp age ownrent income incomesq , wvar(income) type(abse) noconst /* 12.3a */
wls0 exp age ownrent income incomesq , wvar(incomesq) type(abse) noconst /* 12.3b */
wls0 exp age ownrent income incomesq , wvar(income incomesq) type(e2) noconst /* 12.3c */
wls0 exp age ownrent income incomesq , wvar(income incomesq) type(abse) noconst /* 12.3d */
wls0 exp age ownrent income incomesq , wvar(income incomesq) type(loge2) /* 12.3e */
wls0 exp age ownrent income incomesq , wvar(income incomesq) type(xb2) /* 12.3h */
regress exp age ownrent income incomesq [aw = 1/income]
regress exp age ownrent income incomesq [aw = 1/incomesq]
regress exp age ownrent income incomesq
predict e, resid
generate ee=e^2
regress ee income incomesq, noconst
predict p1
regress exp age ownrent income incomesq [aw = 1/p1]
generate abse=abs(e)
regress abse income incomesq, noconst
predict p2
regress exp age ownrent income incomesq [aw = 1/p2]
generate logee=log(ee)
regress logee income incomesq
predict p3
replace p3 = exp(p3)
regress exp age ownrent income incomesq [aw = 1/p3]
generate loginc = log(income)
regress logee loginc
predict p4
replace p4 = exp(p4)
regress exp age ownrent income incomesq [aw=1/p4]
reghv exp age ownrent income incomesq, var(loginc)
regress exp age ownrent income incomesq
predict p
generate p5 = p^2
regress exp age ownrent income incomesq [aw=1/p5]
reghv exp age ownrent income incomesq, var(income incomesq)