I found that margins gives an inaccurate estimate after xtreg, fe on an unbalanced panel, but it works fine if the panel is balanced. Does anyone know why? Here is an example in Stata 17:
Below is an excerpt from the output for margins on unbalanced panel, which does not tally with summary means.
Code:
*1. Create unbalanced panel webuse nlswork.dta, clear drop if year>69 | hours==. xtset idcode year drop if year==69 & L.year==. tab year *2. Test margins for unbalanced panel xtreg hours year, fe margins, by(year) bysort year: su hours *3. Create balanced panel xtset idcode year drop if year==68 & F.year==. *4. Test margins for balanced panel xtreg hours year, fe margins, by(year) bysort year: su hours
Code:
. margins, by(year) Predictive margins Number of obs = 2,224 Model VCE: Conventional Expression: Linear prediction, predict() Over: year ------------------------------------------------------------------------------ | Delta-method | Margin std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- year | 68 | 37.54182 .1774929 211.51 0.000 37.19394 37.8897 69 | 38.1724 .2313402 165.01 0.000 37.71899 38.62582 ------------------------------------------------------------------------------ . bysort year: su hours ------------------------------------------------------------------------------------------------ -> year = 68 Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- hours | 1,374 37.35007 9.303987 1 84 ------------------------------------------------------------------------------------------------ -> year = 69 Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- hours | 850 38.48235 7.161952 2 70
Comment