use http://www.ats.ucla.edu/stat/examples/imm/imm23, clear
// Data from Kreft and De Leeuw (1998: 58)
xtmixed math || schid:, var
predict means1, reffects
predict means1se, reses
egen pickone = tag(schid)
sort means1
egen means1rank = rank(means1) if pickone == 1
serrbar means1 means1se means1rank if pickone == 1, ///
scale(1.96) yline(0) xlabel(none) ///
xtitle("Schools") ytitle("School effects on math scores") ///
title("Null model") ///
name(means1, replace)
xtmixed math meanses public ratio || schid:, var
predict means2, reffects
predict means2se, reses
serrbar means2 means2se means1rank if pickone == 1, ///
scale(1.96) yline(0) xlabel(none) ///
xtitle("Schools") ytitle("School effects on math scores") ///
title("After controlling for average SES, school type, ///
and student–teacher ratio") ///
name(means2, replace)
graph combine means1 means2, ycommon xcommon col(1)
Reference
Kreft, Ita, and Jan De Leeuw. 1998.
Introducing Multilevel Modeling. Sage.