------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\6_Contextua > l_Effects.smcl log type: smcl opened on: 27 Mar 2020, 17:42:01 . **************************************************************************** . * MLwiN User Manual . * . * 6 Contextual Effects 79 . * . * 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/ . **************************************************************************** . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) 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.60 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 ------------------------------------------------------------------------------ . . . . * 6.1 The impact of school gender on girls' achievement . . . . . . . . . 80 . . generate boysch = (schgend==2) . . generate girlsch = (schgend==3) . . runmlwin normexam cons standlrt girl boysch girlsch, /// > level2(school: cons standlrt) /// > 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 = -4640.56 Deviance = 9281.12 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.1888198 .0513513 -3.68 0.000 -.2894664 -.0881732 standlrt | .554426 .019938 27.81 0.000 .5153482 .5935038 girl | .1682632 .0338217 4.98 0.000 .1019739 .2345525 boysch | .1798664 .0991404 1.81 0.070 -.0144452 .3741779 girlsch | .1748234 .0787633 2.22 0.026 .0204502 .3291966 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0795417 .0159664 .0482482 .1108353 cov(cons,standlrt) | .0201009 .0064875 .0073856 .0328162 var(standlrt) | .0146521 .0044111 .0060065 .0232977 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5501983 .0124031 .5258886 .574508 ------------------------------------------------------------------------------ . . generate boyschXstandlrt = boysch*standlrt . . generate girlschXstandlrt = girlsch*standlrt . . runmlwin normexam cons standlrt girl boysch girlsch /// > boyschXstandlrt girlschXstandlrt, /// > level2(school: cons standlrt) /// > level1(student: cons) initsprevious nopause Model fitted using initial values specified as parameter estimates from previou > s model 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.71 Number of iterations = 4 Log likelihood = -4640.4256 Deviance = 9280.8513 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.1810165 .053569 -3.38 0.001 -.2860099 -.0760231 standlrt | .5639007 .0272401 20.70 0.000 .510511 .6172904 girl | .1676371 .033843 4.95 0.000 .1013059 .2339682 boysch | .1665862 .1103825 1.51 0.131 -.0497596 .382932 girlsch | .1568717 .0866395 1.81 0.070 -.0129387 .3266821 boyschXsta~t | -.0159318 .0575576 -0.28 0.782 -.1287427 .096879 girlschXst~t | -.022419 .0448571 -0.50 0.617 -.1103374 .0654994 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0794621 .0159519 .048197 .1107272 cov(cons,standlrt) | .0200452 .0064732 .007358 .0327324 var(standlrt) | .0145713 .0043962 .0059549 .0231877 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5501945 .012403 .5258851 .5745039 ------------------------------------------------------------------------------ . . . . * 6.2 Contextual effects of school intake ability averages . . . . . . . .83 . . generate mid = (schav==2) . . generate high = (schav==3) . . runmlwin normexam cons standlrt girl boysch girlsch mid high, /// > level2(school: cons standlrt) /// > 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.66 Number of iterations = 4 Log likelihood = -4639.2217 Deviance = 9278.4434 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.2648068 .081525 -3.25 0.001 -.4245929 -.1050208 standlrt | .5515512 .0200525 27.51 0.000 .5122491 .5908534 girl | .1671318 .0338218 4.94 0.000 .1008423 .2334214 boysch | .1869666 .097693 1.91 0.056 -.0045081 .3784414 girlsch | .1569925 .0777398 2.02 0.043 .0046252 .3093597 mid | .0669378 .0852787 0.78 0.432 -.1002054 .234081 high | .1743664 .0986769 1.77 0.077 -.0190368 .3677696 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0707554 .0144074 .0425175 .0989934 cov(cons,standlrt) | .0160908 .0060256 .0042809 .0279008 var(standlrt) | .0147031 .004428 .0060244 .0233817 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5501641 .0124027 .5258553 .5744729 ------------------------------------------------------------------------------ . . generate standlrtXmid = standlrt*mid . . generate standlrtXhigh = standlrt*high . . runmlwin normexam cons standlrt girl boysch girlsch /// > mid high standlrtXmid standlrtXhigh, /// > level2(school: cons standlrt) /// > 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.65 Number of iterations = 4 Log likelihood = -4634.242 Deviance = 9268.4839 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.3472495 .0877981 -3.96 0.000 -.5193307 -.1751684 standlrt | .455028 .0418097 10.88 0.000 .3730825 .5369736 girl | .1676012 .0338045 4.96 0.000 .1013455 .2338569 boysch | .1892797 .097687 1.94 0.053 -.0021832 .3807426 girlsch | .1608622 .0777235 2.07 0.038 .008527 .3131974 mid | .1443208 .0942132 1.53 0.126 -.0403338 .3289754 high | .290441 .1057629 2.75 0.006 .0831495 .4977325 standlrtXmid | .0922238 .0486506 1.90 0.058 -.0031296 .1875772 standlrtXh~h | .1804621 .0549303 3.29 0.001 .0728008 .2881235 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .069315 .0141425 .0415961 .0970338 cov(cons,standlrt) | .0135929 .0054189 .0029721 .0242138 var(standlrt) | .0107221 .0036853 .003499 .0179451 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5502787 .0124039 .5259675 .5745899 ------------------------------------------------------------------------------ . . generate temp = standlrt . . . . foreach var of varlist cons standlrt girl boysch girlsch mid standlrtXmid { 2. . replace `var' = 0 3. . } (4,059 real changes made) (4,059 real changes made) (2,436 real changes made) (513 real changes made) (1,377 real changes made) (2,263 real changes made) (2,263 real changes made) . . predict hilodiff . . predict hilodiff_se, stdp . . generate hilodiff_lo = hilodiff - 1.96*hilodiff_se . . generate hilodiff_hi = hilodiff + 1.96*hilodiff_se . . replace standlrt = temp (4,059 real changes made) . . keep if high==1 (2,903 observations deleted) . . keep high standlrtXhigh hilodiff hilodiff_lo hilodiff_hi . . duplicates drop Duplicates in terms of all variables (1,094 observations deleted) . . sort standlrt . . line hilodiff standlrt . . twoway (line hilodiff standlrt) /// > (line hilodiff_lo standlrt, lcolor(dknavy) lpattern(dash)) /// > (line hilodiff_hi standlrt, lcolor(dknavy) lpattern(dash)), /// > legend(off) . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . 87 . . . . **************************************************************************** . exit end of do-file