/*** DAY 4 CODE ***/ use http://www.stata-press.com/data/mlmus2/gcse, clear regress gcse lrt if school==1 predict p_gcse, xb twoway (scatter gcse lrt) (line p_gcse lrt, sort) if school==1, xtitle(LRT) ytitle(GCSE) egen num = count(gcse), by(school) statsby inter=_b[_cons] slope=_b[lrt], by(school) saving(ols): regress gcse lrt if num>4 sort school merge school using ols drop _merge twoway scatter slope inter, xtitle(Intercept) ytitle(Slope) egen pickone = tag(school) summarize inter slope if pickone==1 correlate inter slope if pickone==1, covariance generate pred = inter + slope*lrt sort school lrt twoway (line pred lrt, connect(ascending)), xtitle(LRT) ytitle(Fitted regression lines) ** 4.5.1 Using xtmixed xtmixed gcse lrt || school:, mle estimates store ri xtmixed gcse lrt || school: lrt, cov(unstructured) mle estat recovariance estimates store rc *** 4.6 Testing the slope variance lrtest ri rc