------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\5_Graphical > _Procedures_for_Exploring_the_Model.smcl log type: smcl opened on: 27 Mar 2020, 17:41:49 . **************************************************************************** . * MLwiN User Manual . * . * 5 Graphical Procedures for Exploring the Model 65 . * . * Rasbash, J., Steele, F., Browne, W. J. and Goldstein, H. (2012). . * A User’s Guide to MLwiN, v2.26. Centre for Multilevel Modelling, . * University of Bristol. . **************************************************************************** . * Stata do-file to replicate all analyses using runmlwin . * . * George Leckie and Chris Charlton, . * Centre for Multilevel Modelling, 2012 . * http://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . * 5.1 Displaying multiple graphs . . . . . . . . . . . . . . . . . . . . .65 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons standlrt, /// > level2(school: cons, residuals(u)) /// > level1(student: cons) nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ school | 65 2 62.4 198 ----------------------------------------------------------- Run time (seconds) = 0.61 Number of iterations = 4 Log likelihood = -4678.6211 Deviance = 9357.2423 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .0023908 .0400224 0.06 0.952 -.0760516 .0808332 standlrt | .5633712 .0124654 45.19 0.000 .5389395 .5878029 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0921275 .0181475 .0565591 .127696 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .565731 .0126585 .5409208 .5905412 ------------------------------------------------------------------------------ . . egen pickone = tag(school) . . egen u0rank = rank(u0) if pickone==1 (3994 missing values generated) . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) . . scatter normexam standlrt, /// > yline(0) xline(0) ylabel(-4(1)4) xlabel(-4(1)4) aspectratio(1) . . . . * 5.2 Highlighting in graphs . . . . . . . . . . . . . . . . . . . . . . .68 . . predict xb . . generate xbu = xb + u0 . . sort school standlrt . . line xbu standlrt, connect(a) . . twoway (line xbu standlrt, connect(a)) /// > (line xb standlrt, lwidth(*3) lcolor(black)) . . list school u0rank if pickone==1 & u0rank==65 +-----------------+ | school u0rank | |-----------------| 3385. | 53 65 | +-----------------+ . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) /// > addplot( /// > (scatter u0 u0rank if pickone==1 & school==53, msize(*2) mcol > or(maroon)) /// > ) legend(order(3 "School 53")) . . twoway (line xbu standlrt, connect(a)) /// > (line xb standlrt, lwidth(*3) lcolor(black)) /// > (line xbu standlrt if school==53, lwidth(*2) lcolor(maroon)), /// > legend(order(3 "School 53")) . . twoway (scatter normexam standlrt) /// > (scatter normexam standlrt if school==53, msize(*2) mcolor(maroon)), > /// > legend(order(2 "School 53")) . . bysort school: generate size = _N . . list school size u0rank if pickone==1 & inrange(u0rank,28,32) +------------------------+ | school size u0rank | |------------------------| 487. | 8 102 32 | 2979. | 47 82 30 | 3056. | 48 2 29 | 3285. | 51 58 28 | 3757. | 61 64 31 | +------------------------+ . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) /// > addplot( /// > (scatter u0 u0rank if pickone==1 & school==53, msize(*2) mcol > or(maroon)) /// > (scatter u0 u0rank if pickone==1 & school==48, msize(*2) mcol > or(green)) /// > ) legend(order(3 "School 53" 4 "School 48")) . . twoway (line xbu standlrt, connect(a)) /// > (line xb standlrt, lwidth(*3) lcolor(black)) /// > (line xbu standlrt if school==53, lwidth(*3) lcolor(maroon)) /// > (line xbu standlrt if school==48, lwidth(*3) lcolor(green)), /// > legend(order(2 "The average school" 3 "School 53" 4 "School 48")) . . twoway (scatter normexam standlrt) /// > (scatter normexam standlrt if school==53, msize(*2) mcolor(maroon)) / > // > (scatter normexam standlrt if school==48, msize(*2) mcolor(green)), / > // > legend(order(2 "School 53" 3 "School 48")) . . list school u0rank if pickone==1 & u0rank==1 +-----------------+ | school u0rank | |-----------------| 3643. | 59 1 | +-----------------+ . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) /// > addplot( /// > (scatter u0 u0rank if pickone==1 & school==53, msize(*2) mcol > or(maroon)) /// > (scatter u0 u0rank if pickone==1 & school==59, msize(*2) mcol > or(green)) /// > ) legend(order(3 "School 53" 4 "School 59")) . . twoway (line xbu standlrt, connect(a)) /// > (line xb standlrt, lwidth(*3) lcolor(black)) /// > (line xbu standlrt if school==53, lwidth(*3) lcolor(maroon)) /// > (line xbu standlrt if school==59, lwidth(*3) lcolor(green)), /// > legend(order(2 "The average school" 3 "School 53" 4 "School 59")) . . twoway (scatter normexam standlrt) /// > (scatter normexam standlrt if school==53, msize(*2) mcolor(maroon)) / > // > (scatter normexam standlrt if school==59, msize(*2) mcolor(green)), / > // > legend(order(2 "School 53" 3 "School 59")) . . drop xb xbu u0 u0 u0se u0rank . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt, residuals(u, sampling)) /// > level1(student: cons) nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ school | 65 2 62.4 198 ----------------------------------------------------------- Run time (seconds) = 0.70 Number of iterations = 4 Log likelihood = -4658.435 Deviance = 9316.87 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0115051 .039783 -0.29 0.772 -.0894783 .066468 standlrt | .5567305 .019937 27.92 0.000 .5176547 .5958062 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0904446 .017924 .0553142 .1255749 cov(cons,standlrt) | .0180414 .0067229 .0048649 .031218 var(standlrt) | .0145361 .0044139 .0058851 .0231872 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5536575 .0124818 .5291937 .5781214 ------------------------------------------------------------------------------ . . predict xb . . generate xbu = xb + u0 + u1*standlrt . . twoway (scatter u0 u1) /// > (scatter u0 u1 if pickone==1 & school==53, msize(*2) mcolor(maroon)) > /// > (scatter u0 u1 if pickone==1 & school==59, msize(*2) mcolor(green)), > /// > ytitle("Intercept") xtitle("Slope") /// > yline(0) xline(0) ylabel(-1(.25)1) xlabel(-1(.25)1) aspectratio(1) // > / > legend(order(2 "School 53" 3 "School 59")) . . twoway (line xbu standlrt, connect(a)) /// > (line xb standlrt, lwidth(*3) lcolor(black)) /// > (line xbu standlrt if school==53, lwidth(*3) lcolor(maroon)) /// > (line xbu standlrt if school==59, lwidth(*3) lcolor(green)), /// > legend(order(3 "School 53" 4 "School 59")) . . twoway (scatter normexam standlrt) /// > (scatter normexam standlrt if school==53, msize(*2) mcolor(maroon)) / > // > (scatter normexam standlrt if school==59, msize(*2) mcolor(green)), / > // > legend(order(2 "School 53" 3 "School 59")) . . generate xbu_lo = xbu - 1.96*sqrt(u0var + 2*u0u1cov*standlrt + u1var*standlrt > ^2) . . generate xbu_hi = xbu + 1.96*sqrt(u0var + 2*u0u1cov*standlrt + u1var*standlrt > ^2) . . twoway (line xb standlrt, lwidth(*3) lcolor(black)) /// > (line xbu standlrt if school==53, lwidth(*3) lcolor(maroon)) /// > (line xbu_lo standlrt if school==53, lcolor(maroon) lpattern(dash)) / > // > (line xbu_hi standlrt if school==53, lcolor(maroon) lpattern(dash)) / > // > (line xbu standlrt if school==59, lwidth(*3) lcolor(green)) /// > (line xbu_lo standlrt if school==59, lcolor(green) lpattern(dash)) // > / > (line xbu_hi standlrt if school==59, lcolor(green) lpattern(dash)), / > // > legend(order(2 "School 53" 5 "School 59")) . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . 77 . . . . **************************************************************************** . exit end of do-file