version 12.0 drop _all set more 1 use "c:\users\john\documents\teach\ox_course\ghqdata2", clear capture log close log using "c:\users\john\documents\teach\ox_course\ghq_ex.log", replace ge agesq=age*age /***CREATE INDICATOR FOR CONSECUTIVE WAVES***/ sort pid wave by pid: ge conwave=1 if wave-wave[_n-1]==1 by pid: replace conwave=0 if wave-wave[_n-1]>1 /***Generate lagged value of log income***/ by pid: ge lfihhmn_1=lfihhmn[_n-1] if conwave==1 /***Describe data***/ xtset pid wave xtsum ghq36 ghq12 age sex mastat nchild retired unemploy employ lfihhmn ave1_5 xttab unemploy xttab retired xttab employ ge other=1 if employ==0 & unemploy==0 & retired==0 replace other=0 if employ==1 | unemploy==1 | retired==1 xttrans unemploy xttrans retired xttrans other /***Estimate fe and re models with lagged average income and test for differences between fe and re estimators***/ xi: reg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn ave1_5 , r cl(pid) xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn ave1_5 , fe est store fxd xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn ave1_5 , re hausman fxd . /***Estimate simple fe and re static models and test for differences between fe and re estimators***/ xi: reg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn , r cl(pid) xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn , fe est store fxd2 xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn , re hausman fxd2 . /***Estimate fe and re models with lagged income and test for differences between fe and re estimators***/ xi: reg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn lfihhmn_1, r cl(pid) xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn lfihhmn_1, fe est store fxd3 xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn lfihhmn_1, re hausman fxd3 . /***Create within person means***/ egen miage=mean(age), by(pid) egen miagesq=mean(agesq), by(pid) egen minchild=mean(nchild), by(pid) egen milfihhmn=mean(lfihhmn), by(pid) egen miretired=mean(retired), by(pid) egen miunemploy=mean(unemploy), by(pid) egen miother=mean(other), by(pid) /***Test model without marital status using Mundlak method***/ xi: xtreg ghq36 age agesq sex i.mastat nchild retired unemploy other lfihhmn miage miagesq minchild miretired miunemploy miother milfihhmn, re test miage miagesq minchild miretired miunemploy miother milfihhmn /***Compare with Hausman test***/ xi: xtreg ghq36 age agesq sex nchild retired unemploy other lfihhmn , fe est store fxd4 xi: xtreg ghq36 age agesq sex nchild retired unemploy other lfihhmn , re hausman fxd4 . /***Simple bivariate model***/ xi: xtreg ghq36 lfihhmn milfihhmn, re xi: xtreg ghq36 lfihhmn , fe est store fxd5 xi: xtreg ghq36 lfihhmn , re hausman fxd5 . exit