------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\3.4.smcl log type: smcl opened on: 27 Mar 2020, 18:21:17 . **************************************************************************** . * Module 3: Multiple Regression Stata Practicals . * . * P3.4: Interaction Effects . * . * 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/ . **************************************************************************** . . * P3.4.1 Model with fixed cohort effect for boys and girls . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/3.4.dta", clear . . runmlwin score cons cohort90 female, /// > 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.64 Number of iterations = 2 Log likelihood = -141973.67 Deviance = 283947.35 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 29.72097 .1244808 238.76 0.000 29.47699 29.96495 cohort90 | 1.315917 .0159878 82.31 0.000 1.284582 1.347253 female | 1.913244 .1714671 11.16 0.000 1.577174 2.249313 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 248.7539 1.908192 245.0139 252.4939 ------------------------------------------------------------------------------ . . predict predscore . . egen pickone = tag(cohort90 female) . . twoway (line predscore cohort90 if female==0 & pickone==1) /// > (line predscore cohort90 if female==1 & pickone==1) . . twoway (line predscore cohort90 if female==0, lpattern(solid)) /// > (line predscore cohort90 if female==1, lpattern(dash)) /// > if pickone==1, /// > legend(order(1 "Boys" 2 "Girls")) . . . . * P3.4.2 Fitting separate models for boys and girls . . runmlwin score cons cohort90 if female==0, /// > level1(caseid: cons) /// > mlwinsettings(optimat) nopause MLwiN 3.05 multilevel model Number of obs = 16055 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.61 Number of iterations = 2 Log likelihood = -67244.24 Deviance = 134488.48 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 29.72546 .1258898 236.12 0.000 29.47872 29.9722 cohort90 | 1.259275 .0236106 53.34 0.000 1.212999 1.305551 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 254.3873 2.839261 248.8225 259.9521 ------------------------------------------------------------------------------ . . runmlwin score cons cohort90 if female==1, /// > level1(caseid: cons) /// > mlwinsettings(optimat) nopause MLwiN 3.05 multilevel model Number of obs = 17933 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.58 Number of iterations = 2 Log likelihood = -74719.879 Deviance = 149439.76 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 31.61153 .1169548 270.29 0.000 31.3823 31.84076 cohort90 | 1.365927 .0217079 62.92 0.000 1.323381 1.408474 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 243.5567 2.572105 238.5155 248.5979 ------------------------------------------------------------------------------ . . . . * P3.4.3 Allowing for sex-specific trends in a pooled analysis: . * interaction effects . . generate cohort90Xfemale = cohort90*female . . runmlwin score cons cohort90 female cohort90Xfemale, /// > 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.68 Number of iterations = 2 Log likelihood = -141968.13 Deviance = 283936.26 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 29.72546 .1244678 238.82 0.000 29.4815 29.96941 cohort90 | 1.259275 .0233439 53.94 0.000 1.213521 1.305028 female | 1.886072 .1716333 10.99 0.000 1.549677 2.222467 cohort90Xf~e | .1066528 .0320323 3.33 0.001 .0438706 .169435 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 248.6728 1.90757 244.934 252.4116 ------------------------------------------------------------------------------ . . drop predscore . . predict predscore . . twoway (line predscore cohort90 if female==0, lpattern(solid)) /// > (line predscore cohort90 if female==1, lpattern(dash)) /// > if pickone==1, /// > legend(order(1 "Boys" 2 "Girls")) . . . . * P3.4.4 Allowing the trend in attainment to depend on social class . . generate cohort90Xsclass1 = cohort90*sclass1 . . generate cohort90Xsclass2 = cohort90*sclass2 . . generate cohort90Xsclass4 = cohort90*sclass4 . . runmlwin score cons cohort90 sclass1 sclass2 sclass4 /// > cohort90Xsclass1 cohort90Xsclass2 cohort90Xsclass4, /// > 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.76 Number of iterations = 2 Log likelihood = -139257.13 Deviance = 278514.27 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 24.89051 .1504042 165.49 0.000 24.59572 25.1853 cohort90 | 1.378295 .0288295 47.81 0.000 1.32179 1.4348 sclass1 | 13.22412 .20581 64.25 0.000 12.82074 13.6275 sclass2 | 6.865214 .2093862 32.79 0.000 6.454825 7.275603 sclass4 | -4.392561 .2946125 -14.91 0.000 -4.969991 -3.815132 cohort90Xs~1 | -.3250794 .0386262 -8.42 0.000 -.4007854 -.2493734 cohort90Xs~2 | -.244681 .0398638 -6.14 0.000 -.3228127 -.1665494 cohort90Xs~4 | .1839794 .0535124 3.44 0.001 .079097 .2888618 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 212.0053 1.626293 208.8178 215.1928 ------------------------------------------------------------------------------ . . drop predscore pickone . . predict predscore . . egen pickone = tag(cohort90 sclass) . . twoway (line predscore cohort90 if sclass==1, lpattern(solid)) /// > (line predscore cohort90 if sclass==2, lpattern(dash)) /// > (line predscore cohort90 if sclass==3, lpattern(dot)) /// > (line predscore cohort90 if sclass==4, lpattern(dash_dot)) /// > if pickone==1, /// > legend(order(1 "sclass=1" 2 "sclass=1" 3 "sclass=3" 4 "sclass=4")) . . replace predscore = predscore - (24.891 + 1.378*cohort90) (33,988 real changes made) . . twoway (line predscore cohort90 if sclass==1, lpattern(solid)) /// > (line predscore cohort90 if sclass==2, lpattern(dash)) /// > (line predscore cohort90 if sclass==3, lpattern(dot)) /// > (line predscore cohort90 if sclass==4, lpattern(dash_dot)) /// > if pickone==1, /// > legend(order(1 "sclass=1" 2 "sclass=1" 3 "sclass=3" 4 "sclass=4")) . . test cohort90Xsclass1 cohort90Xsclass2 cohort90Xsclass4 ( 1) [FP1]cohort90Xsclass1 = 0 ( 2) [FP1]cohort90Xsclass2 = 0 ( 3) [FP1]cohort90Xsclass4 = 0 chi2( 3) = 139.72 Prob > chi2 = 0.0000 . end of do-file