------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\11.4.smcl log type: smcl opened on: 27 Mar 2020, 18:22:33 . **************************************************************************** . * Module 11: Three and Higher-Level Models - Stata Practical . * . * P11.4: Adding Random Coefficients . * . * George Leckie . * Centre for Multilevel Modelling, 2011 . **************************************************************************** . * Stata do-file to replicate all analyses using runmlwin . * . * George Leckie . * Centre for Multilevel Modelling, 2013 . * http://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . * P11.4.1 Adding classroom level random coefficients . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/11.4.dta", clear . . tabulate condition, generate(c) condition | Freq. Percent Cum. ------------+----------------------------------- Neither | 421 26.31 26.31 CC only | 380 23.75 50.06 TV only | 416 26.00 76.06 CC and TV | 383 23.94 100.00 ------------+----------------------------------- Total | 1,600 100.00 . . runmlwin postthks cons prethks cc tv ccXtv, /// > level3(schoolid: cons) /// > level2(classid: c1 c2 c3 c4, diagonal) /// > level1(studentid: cons) /// > nopause MLwiN 3.05 multilevel model Number of obs = 1600 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ schoolid | 28 18 57.1 137 classid | 135 1 11.9 28 ----------------------------------------------------------- Run time (seconds) = 0.74 Number of iterations = 9 Log likelihood = -2678.1101 Deviance = 5356.2201 ------------------------------------------------------------------------------ postthks | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 1.695072 .1162999 14.58 0.000 1.467128 1.923016 prethks | .308037 .0258381 11.92 0.000 .2573952 .3586788 cc | .6426721 .1448793 4.44 0.000 .3587139 .9266304 tv | .1618576 .1485004 1.09 0.276 -.1291978 .452913 ccXtv | -.3056365 .2041117 -1.50 0.134 -.705688 .094415 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 3: schoolid | var(cons) | .0249982 .0192055 -.0126439 .0626404 -----------------------------+------------------------------------------------ Level 2: classid | var(c1) | .0647161 .0515377 -.0362958 .1657281 var(c2) | .0499676 .0500099 -.0480501 .1479852 var(c3) | .1110816 .0656028 -.0174975 .2396607 var(c4) | .027346 .0435949 -.0580984 .1127903 -----------------------------+------------------------------------------------ Level 1: studentid | var(cons) | 1.602349 .0589016 1.486904 1.717794 ------------------------------------------------------------------------------ . . estimates store model5 . . lrtest model3 model5 Likelihood-ratio test LR chi2(3) = 1.14 (Assumption: model3 nested in model5) Prob > chi2 = 0.7678 . . . . * P11.4.2 Adding cross-level interactions . . generate ccXprethks = cc*prethks . . generate tvXprethks = tv*prethks . . generate ccXtvXprethks = ccXtv*prethks . . runmlwin postthks cons prethks cc tv ccXtv ccXprethks tvXprethks ccXtvXprethk > s, /// > level3(schoolid: cons) /// > level2(classid: cons) /// > level1(studentid: cons) /// > nopause MLwiN 3.05 multilevel model Number of obs = 1600 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ schoolid | 28 18 57.1 137 classid | 135 1 11.9 28 ----------------------------------------------------------- Run time (seconds) = 0.60 Number of iterations = 4 Log likelihood = -2675.7727 Deviance = 5351.5453 ------------------------------------------------------------------------------ postthks | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 1.634877 .152471 10.72 0.000 1.336039 1.933715 prethks | .336214 .0528494 6.36 0.000 .232631 .439797 cc | .603041 .2134796 2.82 0.005 .1846288 1.021453 tv | .1744531 .2103819 0.83 0.407 -.2378878 .586794 ccXtv | -.0103224 .2951263 -0.03 0.972 -.5887594 .5681146 ccXprethks | .019042 .0742047 0.26 0.797 -.1263965 .1644805 tvXprethks | .0023994 .0729853 0.03 0.974 -.140649 .1454479 ccXtvXpret~s | -.1563684 .1032456 -1.51 0.130 -.358726 .0459892 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 3: schoolid | var(cons) | .0252875 .019511 -.0129534 .0635285 -----------------------------+------------------------------------------------ Level 2: classid | var(cons) | .063637 .0275943 .0095532 .1177209 -----------------------------+------------------------------------------------ Level 1: studentid | var(cons) | 1.596175 .0586747 1.481174 1.711175 ------------------------------------------------------------------------------ . . estimates store model6 . . lrtest model3 model6 Likelihood-ratio test LR chi2(3) = 5.81 (Assumption: model3 nested in model6) Prob > chi2 = 0.1211 . . predict pred . . twoway /// > (connect pred prethks if condition==1) /// > (connect pred prethks if condition==2) /// > (connect pred prethks if condition==3) /// > (connect pred prethks if condition==4) . . twoway /// > (connect pred prethks if condition==1) /// > (connect pred prethks if condition==2) /// > (connect pred prethks if condition==3) /// > (connect pred prethks if condition==4), /// > ylabel(1(1)5) xlabel(0(1)7) /// > ytitle("Predicted postintervention THKS score") /// > legend(order(1 "Neither" 2 "CC only" 3 "TV only" 4 "CC & TV") rows(1) > ) . . end of do-file