------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\5.1.smcl log type: smcl opened on: 27 Mar 2020, 18:21:28 . **************************************************************************** . * Module 5: Introduction to Multilevel Modelling Stata Practicals . * . * P5.1: Comparing Groups using Multilevel Modelling . * . * George Leckie . * Centre for Multilevel Modelling, 2010 . **************************************************************************** . * Stata do-file to replicate all analyses using runmlwin . * . * George Leckie . * Centre for Multilevel Modelling, 2013 . * http://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/5.1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/5.1.dta obs: 33,988 vars: 10 2 Aug 2013 17:08 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- caseid float %9.0g Case ID schoolid int %9.0g School ID score byte %9.0g Score cons byte %9.0g Constant cohort90 byte %9.0g Cohort female byte %9.0g Female sclass byte %9.0g Social class schtype byte %9.0g School type schurban byte %9.0g School urban-rural classification schdenom byte %9.0g School denomination ------------------------------------------------------------------------------- Sorted by: . . . . * P5.1.1 A multilevel model of attainment with school effects . . runmlwin score cons, /// > level2(schoolid: cons, residuals(u)) /// > level1(caseid: cons) /// > nopause MLwiN 3.05 multilevel model Number of obs = 33988 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ schoolid | 508 1 66.9 190 ----------------------------------------------------------- Run time (seconds) = 0.83 Number of iterations = 4 Log likelihood = -143269.53 Deviance = 286539.06 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 30.60059 .3693283 82.85 0.000 29.87672 31.32446 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 60.9869 4.255917 52.64546 69.32835 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 258.3594 1.996576 254.4461 262.2726 ------------------------------------------------------------------------------ . . estimates store nullmodel . . runmlwin score cons, /// > level1(caseid: cons) /// > mlwinsettings(optimat) nopause MLwiN 3.05 multilevel model Number of obs = 33988 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.63 Number of iterations = 2 Log likelihood = -145144.42 Deviance = 290288.84 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 31.09462 .0939156 331.09 0.000 30.91055 31.27869 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 299.7787 2.299603 295.2715 304.2858 ------------------------------------------------------------------------------ . . estimates restore nullmodel (results nullmodel are active now) . . . . * P5.1.2 Examining school effects (residuals) . . egen pickone = tag(schoolid) . . sort u0 . . generate u0rank = sum(pickone) . . sort schoolid . . list schoolid u0 u0se u0rank if pickone==1 & schoolid<=10 +------------------------------------------+ | schoolid u0 u0se u0rank | |------------------------------------------| 15. | 1 -11.84058 2.413168 37 | 151. | 2 3.206283 1.3513 337 | 252. | 3 3.39593 1.539011 344 | 319. | 4 -7.414682 2.099283 73 | 388. | 5 3.426139 1.667874 345 | |------------------------------------------| 530. | 6 12.43349 1.447894 487 | 651. | 7 -1.65189 1.50269 199 | 720. | 8 20.9779 2.050453 508 | 754. | 9 -8.691228 6.437568 59 | 773. | 10 1.737323 1.935835 291 | +------------------------------------------+ . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) . end of do-file