------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\4_Random_In > tercept_and_Random_Slope_Models.smcl log type: smcl opened on: 27 Mar 2020, 17:41:43 . **************************************************************************** . * MLwiN User Manual . * . * 4 Random Intercept and Random Slope Models 47 . * . * 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/ . **************************************************************************** . . * 4.1 Random intercept models . . . . . . . . . . . . . . . . . . . . . . 47 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . scatter normexam standlrt, /// > yline(0) xline(0) ylabel(-4(1)4) xlabel(-4(1)4) aspectratio(1) . . runmlwin normexam cons standlrt, level1(student: cons) nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.59 Number of iterations = 2 Log likelihood = -4880.2547 Deviance = 9760.5094 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0011911 .0126392 -0.09 0.925 -.0259635 .0235812 standlrt | .5950568 .012727 46.76 0.000 .5701124 .6200012 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .6484188 .0143933 .6202084 .6766292 ------------------------------------------------------------------------------ . . 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.63 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 ------------------------------------------------------------------------------ . . . . * 4.2 Graphing predicted school lines from a random intercept model . . . 51 . . predict xbu . . line xbu standlrt . . egen pickone = tag(school) . . list u0 if pickone==1 & school<=6 +----------+ | u0 | |----------| 1. | .3737601 | 74. | .5020428 | 129. | .5038885 | 181. | .0181311 | 260. | .2404306 | |----------| 295. | .541395 | +----------+ . . replace xbu = xbu + u0 (4,059 real changes made) . . drop u0* . . line xbu standlrt . . sort school standlrt . . line xbu standlrt, connect(a) . . drop xbu . . . . * 4.3 The effect of clustering on the standard errors of coeficients . . .58 . . generate boysch = (schgend==2) . . generate girlsch = (schgend==3) . . runmlwin normexam cons standlrt boysch girlsch, /// > level2(school: cons) 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.62 Number of iterations = 4 Log likelihood = -4674.7106 Deviance = 9349.4213 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0870373 .0511181 -1.70 0.089 -.1872269 .0131523 standlrt | .5637917 .0124573 45.26 0.000 .5393759 .5882075 boysch | .0968799 .1089092 0.89 0.374 -.1165782 .310338 girlsch | .2451099 .0849725 2.88 0.004 .0785669 .4116529 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0799939 .0159926 .048649 .1113387 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .565765 .0126591 .5409535 .5905764 ------------------------------------------------------------------------------ . . runmlwin normexam cons standlrt boysch girlsch, /// > level1(student: cons) nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.57 Number of iterations = 2 Log likelihood = -4843.564 Deviance = 9687.128 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0960832 .0171346 -5.61 0.000 -.1296664 -.0625 standlrt | .5943331 .0126127 47.12 0.000 .5696126 .6190535 boysch | .1177705 .0391782 3.01 0.003 .0409827 .1945583 girlsch | .2358432 .0274969 8.58 0.000 .1819502 .2897362 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .6368016 .0141354 .6090966 .6645066 ------------------------------------------------------------------------------ . . . . * 4.4 Does the coeficient of standlrt vary across schools? Introducing a . * random slope . . . . . . . . . . . . . . . . . . . . . . . . . . . .59 . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt, 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.62 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 ------------------------------------------------------------------------------ . . . . * 4.5 Graphing predicted school lines from a random slope model . . . . . 62 . . predict xb . . generate rphat = u0 + u1*standlrt . . generate xbu = xb + rphat . . sort school standlrt . . line xbu standlrt, connect(a) . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . 64 . . . . **************************************************************************** . exit end of do-file