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.


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)