------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\7.1.smcl log type: smcl opened on: 27 Mar 2020, 18:22:00 . **************************************************************************** . * Module 7: Multilevel Models for Binary Responses Stata Practicals . * . * P7.1: Two-Level Random Intercept Model . * . * 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/7.1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/7.1.dta obs: 5,366 vars: 18 2 Aug 2013 17:08 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- comm int %9.0g Community ID womid int %9.0g Woman ID antemed byte %9.0g Antenatal from qualified medic cons byte %9.0g Constant bord byte %9.0g Birth order mage byte %9.0g Mother's age at birth urban byte %9.0g Type of region of residence meduc byte %9.0g Maternal education islam byte %9.0g Religion wealth byte %9.0g Wealth index (1 = poorest) magec float %9.0g magecsq float %9.0g meduc2 byte %8.0g meduc3 byte %8.0g wealth2 byte %8.0g wealth3 byte %8.0g wealth4 byte %8.0g wealth5 byte %8.0g ------------------------------------------------------------------------------- Sorted by: . . . . * P7.1.1 Specifying and estimating a two-level model . . runmlwin antemed cons, /// > level2(comm: cons) /// > level1(womid:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > nopause MLwiN 3.05 multilevel model Number of obs = 5366 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, MQL1 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ comm | 361 3 14.9 25 ----------------------------------------------------------- Run time (seconds) = 0.61 Number of iterations = 4 ------------------------------------------------------------------------------ antemed | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .1084604 .056625 1.92 0.055 -.0025225 .2194434 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: comm | var(cons) | .8702256 .0855925 .7024674 1.037984 ------------------------------------------------------------------------------ . . runmlwin antemed cons, /// > level2(comm: cons, residuals(u)) /// > level1(womid:) /// > discrete(distribution(binomial) link(logit) denominator(cons) pql2) / > // > initsprevious nopause Model fitted using initial values specified as parameter estimates from previou > s model MLwiN 3.05 multilevel model Number of obs = 5366 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, PQL2 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ comm | 361 3 14.9 25 ----------------------------------------------------------- Run time (seconds) = 0.82 Number of iterations = 6 ------------------------------------------------------------------------------ antemed | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .1441238 .0711156 2.03 0.043 .0047398 .2835078 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: comm | var(cons) | 1.433333 .1348155 1.169099 1.697566 ------------------------------------------------------------------------------ . . . . * P7.1.2 Interpretation of the null two-level model . . egen pickone = tag(comm) . . sort u0 . . generate u0rank = sum(pickone) . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) . . . . * P7.1.3 Adding an explanatory variable . . drop u0 u0se . . sort comm womid . . runmlwin antemed cons magec, /// > level2(comm: cons, residuals(u)) /// > level1(womid:) /// > discrete(distribution(binomial) link(logit) denominator(cons) pql2) / > // > initsprevious nopause Model fitted using initial values specified as parameter estimates from previou > s model MLwiN 3.05 multilevel model Number of obs = 5366 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, PQL2 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ comm | 361 3 14.9 25 ----------------------------------------------------------- Run time (seconds) = 0.81 Number of iterations = 6 ------------------------------------------------------------------------------ antemed | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .1407911 .0711213 1.98 0.048 .0013959 .2801862 magec | -.0322224 .0051962 -6.20 0.000 -.0424067 -.0220381 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: comm | var(cons) | 1.431372 .1347962 1.167177 1.695568 ------------------------------------------------------------------------------ . . predict predxb . . generate predprob = invlogit(predxb + u0) . . generate predlogit = logit(predprob) . . drop pickone . . egen pickone = tag(comm mage) . . twoway connected predlogit mage if pickone==1, connect(ascending) /// > ytitle(Predicted log-odds) xtitle(Maternal age (years)) . . drop u0 u0se . . runmlwin antemed cons magec magecsq, /// > level2(comm: cons, residuals(u)) /// > level1(womid:) /// > discrete(distribution(binomial) link(logit) denominator(cons) pql2) / > // > initsprevious nopause Model fitted using initial values specified as parameter estimates from previou > s model MLwiN 3.05 multilevel model Number of obs = 5366 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, PQL2 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ comm | 361 3 14.9 25 ----------------------------------------------------------- Run time (seconds) = 0.82 Number of iterations = 6 ------------------------------------------------------------------------------ antemed | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .1808283 .0751754 2.41 0.016 .0334873 .3281694 magec | -.0274695 .0059591 -4.61 0.000 -.0391491 -.0157899 magecsq | -.00106 .0006581 -1.61 0.107 -.0023499 .0002299 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: comm | var(cons) | 1.421564 .1340603 1.158811 1.684318 ------------------------------------------------------------------------------ . . drop predxb predprob predlogit . . predict predxb . . generate predprob = invlogit(predxb + u0) . . generate predlogit = logit(predprob) . . twoway connected predlogit mage if pickone==1, connect(ascending) /// > ytitle(Predicted log-odds) xtitle(Maternal age (years)) . . end of do-file