------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\5.3.smcl log type: smcl opened on: 27 Mar 2020, 18:21:32 . **************************************************************************** . * Module 5: Introduction to Multilevel Modelling Stata Practicals . * . * P5.3: Allowing for Different Slopes across Schools: Random Slope . * Models . * . * 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.3.dta", clear . . runmlwin score cons cohort90, /// > level2(schoolid: cons cohort90, 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) = 1.04 Number of iterations = 6 Log likelihood = -140343.09 Deviance = 280686.18 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 30.60974 .3133825 97.68 0.000 29.99552 31.22396 cohort90 | 1.233926 .0253229 48.73 0.000 1.184294 1.283558 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 42.83833 3.0695 36.82222 48.85444 cov(cons,cohort90) | -1.026486 .177944 -1.37525 -.6777224 var(cohort90) | .1608036 .0186654 .1242201 .1973871 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 215.7395 1.676774 212.4531 219.0259 ------------------------------------------------------------------------------ . . . . * P5.3.1 Testing for random slopes . . . . * P5.3.2 Interpretation of random cohort effects across schools . . . . * P5.3.3 Examining intercept and slope residuals for schools . . runmlwin, correlations 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) = 1.04 Number of iterations = 6 Log likelihood = -140343.09 Deviance = 280686.18 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 30.60974 .3133825 97.68 0.000 29.99552 31.22396 cohort90 | 1.233926 .0253229 48.73 0.000 1.184294 1.283558 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 42.83833 3.0695 36.82222 48.85444 corr(cons,cohort90) | -.3911011 .0580749 -.5049257 -.2772764 var(cohort90) | .1608036 .0186654 .1242201 .1973871 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 215.7395 1.676774 212.4531 219.0259 ------------------------------------------------------------------------------ . . egen pickone = tag(schoolid) . . scatter u1 u0 if pickone==1, yline(0) xline(0) /// > ytitle("Slope of cohort90 (u1j)") xtitle("Intercept (u0j)") . . predict predscore . . egen multiplecohorts = tag(schoolid cohort90) . . bysort schoolid (cohort90): replace multiplecohorts = 0 /// > if cohort90[_N]==cohort90[1] (32 real changes made) . . twoway connected predscore cohort90 if multiplecohorts==1, connect(ascending) . . . . * P5.3.4 Between-school variance as a function of cohort . . twoway function 42.859 + -2.048*x + 0.161*x^2, range(-6 8) . . . . * P5.3.5 Adding a random coefficient for gender (dichotomous x ) . . runmlwin score cons cohort90 female, /// > level2(schoolid: cons cohort90) /// > 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.96 Number of iterations = 6 Log likelihood = -140272.07 Deviance = 280544.14 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 29.58495 .3239988 91.31 0.000 28.94993 30.21998 cohort90 | 1.227348 .0253353 48.44 0.000 1.177691 1.277004 female | 1.944542 .1629806 11.93 0.000 1.625106 2.263978 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 42.55689 3.050323 36.57836 48.53541 cov(cons,cohort90) | -1.032586 .1775349 -1.380548 -.6846238 var(cohort90) | .1614658 .0186814 .1248509 .1980807 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 214.8375 1.669764 211.5648 218.1101 ------------------------------------------------------------------------------ . . runmlwin score cons cohort90 female, /// > level2(schoolid: cons cohort90 female) /// > 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) = 1.24 Number of iterations = 8 Log likelihood = -140269.45 Deviance = 280538.9 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 29.58912 .3176564 93.15 0.000 28.96653 30.21172 cohort90 | 1.227776 .0253469 48.44 0.000 1.178097 1.277455 female | 1.931448 .1738999 11.11 0.000 1.59061 2.272285 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 40.55742 3.139799 34.40352 46.71131 cov(cons,cohort90) | -1.008778 .1787471 -1.359116 -.6584403 var(cohort90) | .1617426 .0186836 .1251234 .1983618 cov(cons,female) | 1.531284 1.194796 -.8104742 3.873041 cov(cohort90,female) | -.0532271 .0885652 -.2268117 .1203575 var(female) | 1.370663 .8245389 -.2454037 2.98673 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 214.5159 1.676374 211.2303 217.8016 ------------------------------------------------------------------------------ . . . * P5.3.6 Adding a random coefficient for social class (categorical x ) . . generate sclass1 = sclass==1 . . generate sclass2 = sclass==2 . . generate sclass4 = sclass==4 . . runmlwin score cons cohort90 female sclass1 sclass2 sclass4, /// > level2(schoolid: cons cohort90) /// > 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) = 1.05 Number of iterations = 6 Log likelihood = -138346.13 Deviance = 276692.25 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 24.60992 .2795386 88.04 0.000 24.06203 25.1578 cohort90 | 1.18287 .0243246 48.63 0.000 1.135194 1.230545 female | 1.961383 .1542814 12.71 0.000 1.658997 2.263769 sclass1 | 11.08587 .2063923 53.71 0.000 10.68135 11.49039 sclass2 | 5.875273 .2040509 28.79 0.000 5.47534 6.275205 sclass4 | -3.737811 .2845323 -13.14 0.000 -4.295484 -3.180138 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 22.49103 1.710975 19.13758 25.84448 cov(cons,cohort90) | -.5861301 .1249077 -.8309447 -.3413156 var(cohort90) | .1510657 .0172269 .1173016 .1848299 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 192.9468 1.499537 190.0077 195.8858 ------------------------------------------------------------------------------ . . runmlwin score cons cohort90 female sclass1 sclass2 sclass4, /// > level2(schoolid: cons cohort90 sclass1 sclass2 sclass4) /// > 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) = 2.57 Number of iterations = 9 Log likelihood = -138306.23 Deviance = 276612.46 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 24.40957 .2288986 106.64 0.000 23.96094 24.85821 cohort90 | 1.18466 .024482 48.39 0.000 1.136676 1.232644 female | 1.966887 .1540756 12.77 0.000 1.664904 2.268869 sclass1 | 11.17499 .2424911 46.08 0.000 10.69972 11.65027 sclass2 | 6.061056 .2158945 28.07 0.000 5.63791 6.484201 sclass4 | -3.202168 .3102503 -10.32 0.000 -3.810247 -2.594088 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: schoolid | var(cons) | 11.00014 1.344156 8.365645 13.63464 cov(cons,cohort90) | -.5640544 .1113397 -.7822762 -.3458325 var(cohort90) | .1560148 .01756 .1215979 .1904318 cov(cons,sclass1) | 4.982215 1.065348 2.894172 7.070258 cov(cohort90,sclass1) | -.1015663 .1215587 -.3398169 .1366843 var(sclass1) | 6.970018 1.664879 3.706915 10.23312 cov(cons,sclass2) | 5.507575 .9308036 3.683234 7.331917 cov(cohort90,sclass2) | -.1056935 .1078575 -.3170904 .1057033 cov(sclass1,sclass2) | 3.856643 1.210375 1.484352 6.228934 var(sclass2) | 2.629686 1.297213 .0871949 5.172176 cov(cons,sclass4) | 8.543706 1.334659 5.927822 11.15959 cov(cohort90,sclass4) | -.4319025 .1582128 -.7419938 -.1218112 cov(sclass1,sclass4) | 2.759615 1.616005 -.4076969 5.926927 cov(sclass2,sclass4) | 2.212117 1.41938 -.5698166 4.994051 var(sclass4) | 6.378459 2.588752 1.304599 11.45232 -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 191.8938 1.514383 188.9256 194.8619 ------------------------------------------------------------------------------ . . display 11.267 + 2*4.813 + 7.136 28.029 . . display 11.267 + 2*5.059 + 3.321 24.706 . . display 11.267 11.267 . . display 11.267 + 2*8.077 + 7.182 34.603 . end of do-file