------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\3.1.smcl log type: smcl opened on: 27 Mar 2020, 18:21:06 . **************************************************************************** . * Module 3: Multiple Regression Stata Practicals . * . * P3.1: Regression with a Single Continuous Explanatory Variable . * . * 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.1.1 Examining the data . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/3.1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/3.1.dta obs: 33,988 vars: 6 2 Aug 2013 17:08 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- caseid float %9.0g Case 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 ------------------------------------------------------------------------------- Sorted by: . . list in 1/20 +----------------------------------------------------+ | caseid score cons cohort90 female sclass | |----------------------------------------------------| 1. | 339 49 1 -6 0 2 | 2. | 340 18 1 -6 0 3 | 3. | 345 46 1 -6 0 4 | 4. | 346 43 1 -6 0 3 | 5. | 352 17 1 -6 0 3 | |----------------------------------------------------| 6. | 353 29 1 -6 0 2 | 7. | 354 15 1 -6 0 3 | 8. | 361 19 1 -6 0 2 | 9. | 362 45 1 -6 0 3 | 10. | 363 12 1 -6 0 1 | |----------------------------------------------------| 11. | 6824 0 1 -4 0 1 | 12. | 6826 0 1 -4 0 3 | 13. | 6827 20 1 -4 0 2 | 14. | 6828 32 1 -4 0 1 | 15. | 6829 0 1 -4 0 2 | |----------------------------------------------------| 16. | 6834 24 1 -4 0 3 | 17. | 6836 23 1 -4 0 2 | 18. | 13206 7 1 -2 0 3 | 19. | 13209 38 1 -2 0 3 | 20. | 13215 46 1 -2 0 1 | +----------------------------------------------------+ . . histogram score, frequency (bin=45, start=0, width=1.6666667) . . summarize score Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- score | 33,988 31.09462 17.31437 0 75 . . tabulate cohort90 Cohort | Freq. Percent Cum. ------------+----------------------------------- -6 | 6,478 19.06 19.06 -4 | 6,325 18.61 37.67 -2 | 5,245 15.43 53.10 0 | 4,371 12.86 65.96 6 | 4,244 12.49 78.45 8 | 7,325 21.55 100.00 ------------+----------------------------------- Total | 33,988 100.00 . . scatter score cohort90 . . table cohort90, contents(freq mean score sd score) row ------------------------------------------------- Cohort | Freq. mean(score) sd(score) ----------+-------------------------------------- -6 | 6,478 23.65545 18.07995 -4 | 6,325 24.77265 17.37533 -2 | 5,245 28.5245 15.93629 0 | 4,371 29.10044 15.76355 6 | 4,244 39.43473 13.55147 8 | 7,325 41.33065 13.00926 | Total | 33,988 31.09462 17.31437 ------------------------------------------------- . . correlate score cohort90 (obs=33,988) | score cohort90 -------------+------------------ score | 1.0000 cohort90 | 0.4089 1.0000 . . . . * P3.1.2 A simple linear regression analysis . . runmlwin score cons cohort90, /// > level1(caseid: cons, residuals(estd, standardised)) /// > mlwinsettings(optimat) nopause MLwiN 3.05 multilevel model Number of obs = 33988 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 1.11 Number of iterations = 2 Log likelihood = -142035.81 Deviance = 284071.62 ------------------------------------------------------------------------------ score | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 30.72873 .0858214 358.05 0.000 30.56052 30.89693 cohort90 | 1.322144 .0160073 82.60 0.000 1.29077 1.353518 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: caseid | var(cons) | 249.6651 1.915182 245.9114 253.4188 ------------------------------------------------------------------------------ . . predict predscore . . line predscore cohort90 . . egen pickone = tag(cohort90) . . line predscore cohort90 if pickone==1 . . egen estd0rank = rank(estd0) . . generate estd0uniform = estd0rank/(_N + 1) . . generate estd0nscore = invnorm(estd0uniform) . . scatter estd0 estd0nscore . . scatter estd0 predscore . . histogram estd0, frequency (bin=45, start=-41.305877, width=1.944667) . end of do-file