Hi. I am using a dynamic random effects model to study the effect of health insurance on self-employment. My outcome variable is a binary and my dataset a panel. I have set the initial conditions and am trying to run a probit. The probit runs fine, but my code appears to fail at the margins command with the error "at values for factor wavefirst do not sum to 1". I'm unable to fathom why and would greatly appreciate any help. My globals are:
global L "l.selfemp l.lnannearniR" //lagged vars
global F "selfemp urban_hukou" // outcome + treatment
global X "age agesq female ethhan married schyrs numchild i.primoccup lnannearniR i.provid" //basic global
global X1 "age agesq married schyrs numchild i.primoccup" // for FE
global X2 "age agesq female ethhan married schyrs numchild i.primoccup i.provid" // Non-lagged
global X3 "age agesq female ethhan" //time-constant variables + age + year
global XT "married schyrs numchild i.primoccup lnannearniR" // time-varying variables
egen wavefirst=min(yr), by(idind)
label var wavefirst "First time R appears in the sample"
foreach v in selfemp {
gen _t1 = `v' if yr==wavefirst
egen `v'_ic=mean(_t1), by(idind)
drop _*
}
foreach v in married schyrs numchild lnannearniR {
gen _t1 = `v' if yr==wavefirst
egen `v'_1=mean(_t1), by(idind)
gen _t2 = `v' if yr>wavefirst`i'
egen `v'_R=mean(_t2), by(idind)
drop _*
}
*dynamic w lags and pre-post
xtprobit $F post#urban_hukou interaction $L $X2 i.wavefirst, vce(robust)
outreg2 using "DynamicModel.xls", append ctitle(Dynamic w Post) bdec(3)
margins, at(wavefirst=(1(1)5)) over(urban_hukou)
local t: variable label selfemp
marginsplot, xdimension(at(wavefirst)) recast(line) xlabel(1(1)6) ytitle("") title("`t'") graphregion(fcolor(white)) plotopts(lwidth(medthick)) ciopts(lwidth(vvthin)) legend(region(fcolor(white)) region(lcolor(white))) saving("DynamicWLag.gph", replace)
Edit: I've managed to narrow the problem down. It appears that my lagged variables (self-employment - lag of the outcome variable; and annual earnings) are causing the problem. Could someone please explain why this may be so?
global L "l.selfemp l.lnannearniR" //lagged vars
global F "selfemp urban_hukou" // outcome + treatment
global X "age agesq female ethhan married schyrs numchild i.primoccup lnannearniR i.provid" //basic global
global X1 "age agesq married schyrs numchild i.primoccup" // for FE
global X2 "age agesq female ethhan married schyrs numchild i.primoccup i.provid" // Non-lagged
global X3 "age agesq female ethhan" //time-constant variables + age + year
global XT "married schyrs numchild i.primoccup lnannearniR" // time-varying variables
egen wavefirst=min(yr), by(idind)
label var wavefirst "First time R appears in the sample"
foreach v in selfemp {
gen _t1 = `v' if yr==wavefirst
egen `v'_ic=mean(_t1), by(idind)
drop _*
}
foreach v in married schyrs numchild lnannearniR {
gen _t1 = `v' if yr==wavefirst
egen `v'_1=mean(_t1), by(idind)
gen _t2 = `v' if yr>wavefirst`i'
egen `v'_R=mean(_t2), by(idind)
drop _*
}
*dynamic w lags and pre-post
xtprobit $F post#urban_hukou interaction $L $X2 i.wavefirst, vce(robust)
outreg2 using "DynamicModel.xls", append ctitle(Dynamic w Post) bdec(3)
margins, at(wavefirst=(1(1)5)) over(urban_hukou)
local t: variable label selfemp
marginsplot, xdimension(at(wavefirst)) recast(line) xlabel(1(1)6) ytitle("") title("`t'") graphregion(fcolor(white)) plotopts(lwidth(medthick)) ciopts(lwidth(vvthin)) legend(region(fcolor(white)) region(lcolor(white))) saving("DynamicWLag.gph", replace)
Edit: I've managed to narrow the problem down. It appears that my lagged variables (self-employment - lag of the outcome variable; and annual earnings) are causing the problem. Could someone please explain why this may be so?
Comment