------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\7_Modelling > _the_Variance_as_a_Function_of_Explanatory_Variables.smcl log type: smcl opened on: 27 Mar 2020, 17:42:06 . ***************************************************************************** > *** . * MLwiN User Manual . * . * 7 Modelling the Variance as a Function of Explanatory Variables > 89 . * . * 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/ . ***************************************************************************** > *** . . * 7.1 A level 1 variance function for two groups . . . . . . . . . . . . . . > .89 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . generate boy = 1 - girl . . runmlwin normexam boy girl, level1(student: boy girl, diagonal) nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.55 Number of iterations = 2 Log likelihood = -5724.7712 Deviance = 11449.542 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- boy | -.1403503 .0254526 -5.51 0.000 -.1902366 -.0904641 girl | .0933195 .0196435 4.75 0.000 .054819 .13182 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: student | var(boy) | 1.051438 .0369096 .9790965 1.12378 var(girl) | .9399692 .0269333 .8871808 .9927575 ------------------------------------------------------------------------------ . . . . * 7.2 Variance functions at level 2 . . . . . . . . . . . . . . . . . . . . . > 95 . . 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.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 ------------------------------------------------------------------------------ . . generate l2varfn = [RP2]var(cons) /// > + 2*[RP2]cov(cons\standlrt)*standlrt /// > + [RP2]var(standlrt)*standlrt^2 . . line l2varfn standlrt, sort . . . . * 7.3 Further elaborating the model for the student-level variance . . . . . > .99 . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) level1(student: cons standlrt) 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.67 Number of iterations = 6 Log likelihood = -4655.7847 Deviance = 9311.5693 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0117394 .0398498 -0.29 0.768 -.0898435 .0663647 standlrt | .5578658 .019824 28.14 0.000 .5190115 .5967201 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0908245 .017994 .055557 .1260921 cov(cons,standlrt) | .0186285 .0067084 .0054802 .0317768 var(standlrt) | .0142293 .0043701 .005664 .0227946 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5532248 .0152057 .5234222 .5830274 cov(cons,standlrt) | -.0147416 .0064032 -.0272916 -.0021916 var(standlrt) | .0006555 .009114 -.0172075 .0185185 ------------------------------------------------------------------------------ . . replace l2varfn = [RP2]var(cons) /// > + 2*[RP2]cov(cons\standlrt)*standlrt /// > + [RP2]var(standlrt)*standlrt^2 (4,059 real changes made) . . generate l1varfn = [RP1]var(cons) /// > + 2*[RP1]cov(cons\standlrt)*standlrt /// > + [RP1]var(standlrt)*standlrt^2 . . line l2varfn l1varfn standlrt, sort . . matrix A = (1,1,0,0,0,1) . . runmlwin normexam cons standlrt girl, /// > level2(school: cons standlrt) /// > level1(student: cons standlrt girl, elements(A)) 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.67 Number of iterations = 4 Log likelihood = -4638.7199 Deviance = 9277.4398 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.1120024 .0433091 -2.59 0.010 -.1968866 -.0271182 standlrt | .5541702 .0199398 27.79 0.000 .515089 .5932514 girl | .1758032 .032359 5.43 0.000 .1123807 .2392257 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0865338 .0172195 .0527842 .1202834 cov(cons,standlrt) | .0195693 .0066549 .006526 .0326126 var(standlrt) | .0145585 .0044062 .0059225 .0231945 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5826129 .0208153 .5418158 .6234101 cov(cons,standlrt) | -.0128095 .0063487 -.0252527 -.0003664 var(girl) | -.0541153 .025887 -.1048528 -.0033778 ------------------------------------------------------------------------------ . . matrix A = (1,1,0,0,1,1) . . runmlwin normexam cons standlrt girl, /// > level2(school: cons standlrt) /// > level1(student: cons standlrt girl, elements(A)) 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 = -4635.7978 Deviance = 9271.5957 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.1120559 .043286 -2.59 0.010 -.1968948 -.0272169 standlrt | .5538978 .0200267 27.66 0.000 .5146462 .5931494 girl | .1753161 .0322887 5.43 0.000 .1120314 .2386008 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0864349 .017195 .0527333 .1201365 cov(cons,standlrt) | .0195737 .0066755 .0064899 .0326574 var(standlrt) | .0147943 .0044509 .0060707 .0235179 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5837113 .0208961 .5427556 .6246669 cov(cons,standlrt) | -.033675 .0099613 -.0531989 -.0141512 cov(standlrt,girl) | .0320916 .0128955 .0068168 .0573664 var(girl) | -.0582681 .0259295 -.1090889 -.0074473 ------------------------------------------------------------------------------ . . replace l2varfn = [RP2]var(cons) /// > + 2*[RP2]cov(cons\standlrt)*standlrt /// > + [RP2]var(standlrt)*standlrt^2 (4,059 real changes made) . . generate l1varfnboys = [RP1]var(cons) /// > + 2*[RP1]cov(cons\standlrt)*standlrt . . generate l1varfngirls = [RP1]var(cons) /// > + (2*[RP1]cov(cons\standlrt) /// > + 2*[RP1]cov(standlrt\girl))*standlrt + [RP1]var(girl) . . line l2varfn l1varfnboys l1varfngirls standlrt, sort . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . . > 106 . . . . ***************************************************************************** > *** . exit end of do-file