------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\11.1.smcl log type: smcl opened on: 27 Mar 2020, 18:22:24 . **************************************************************************** . * Module 11: Three and Higher-Level Models - Stata Practical . * . * P11.1: Examining and Describing the Data . * . * George Leckie . * Centre for Multilevel Modelling, 2011 . **************************************************************************** . * Stata do-file to replicate all analyses using runmlwin . * . * George Leckie . * Centre for Multilevel Modelling, 2013 . * http://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . * P11.1.1 Exploring the three-level data structure . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/11.1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/11.1.dta obs: 1,600 vars: 9 2 Aug 2013 17:08 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- schoolid int %8.0g School ID classid float %12.0g Class ID studentid int %9.0g Student ID postthks byte %8.0g Postintervention THKS cons byte %9.0g Constant prethks byte %8.0g Baseline THKS cc byte %8.0g Classroom curriculum (CC) tv byte %8.0g Television (TV) ccXtv byte %8.0g Interaction (CC*TV) ------------------------------------------------------------------------------- Sorted by: schoolid classid . . summarize Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- schoolid | 1,600 421.9388 112.6662 193 515 classid | 1,600 422042.3 112667.2 193101 515113 studentid | 1,600 800.5 462.0245 1 1600 postthks | 1,600 2.661875 1.382929 0 7 cons | 1,600 1 0 1 1 -------------+--------------------------------------------------------- prethks | 1,600 2.069375 1.26018 0 6 cc | 1,600 .476875 .4996211 0 1 tv | 1,600 .499375 .5001559 0 1 ccXtv | 1,600 .239375 .4268354 0 1 . . list in 1/10, compress +-----------------------------------------------------------------+ | sch~d clas~d stu~d pos~s cons pre~s cc tv ccXtv | |-----------------------------------------------------------------| 1. | 193 193101 1 2 1 1 0 0 0 | 2. | 193 193101 2 2 1 3 0 0 0 | 3. | 193 193101 3 3 1 0 0 0 0 | 4. | 193 193101 4 2 1 3 0 0 0 | 5. | 193 193101 5 1 1 1 0 0 0 | |-----------------------------------------------------------------| 6. | 193 193101 6 2 1 2 0 0 0 | 7. | 193 193101 7 4 1 3 0 0 0 | 8. | 193 193101 8 2 1 3 0 0 0 | 9. | 193 193101 9 3 1 3 0 0 0 | 10. | 193 193101 10 3 1 1 0 0 0 | +-----------------------------------------------------------------+ . . codebook schoolid classid ------------------------------------------------------------------------------- schoolid School ID ------------------------------------------------------------------------------- type: numeric (int) range: [193,515] units: 1 unique values: 28 missing .: 0/1,600 mean: 421.939 std. dev: 112.666 percentiles: 10% 25% 50% 75% 90% 197 405 415 509 514 ------------------------------------------------------------------------------- classid Class ID ------------------------------------------------------------------------------- type: numeric (float) range: [193101,515113] units: 1 unique values: 135 missing .: 0/1,600 mean: 422042 std. dev: 112667 percentiles: 10% 25% 50% 75% 90% 197102 405101 415105 509107 514106 . . egen pickone_school = tag(schoolid) . . egen pickone_class = tag(classid) . . bysort schoolid: egen numclasses = total(pickone_class) . . summarize numclasses if pickone_school==1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- numclasses | 28 4.821429 2.789578 1 13 . . bysort schoolid: generate schoolsize = _N . . bysort classid: generate classsize = _N . . summarize schoolsize if pickone_school==1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- schoolsize | 28 57.14286 30.92011 18 137 . . summarize classsize if pickone_class==1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- classsize | 135 11.85185 6.055118 1 28 . . tabulate cc tv if pickone_school==1 Classroom | curriculum | Television (TV) (CC) | 0 1 | Total -----------+----------------------+---------- 0 | 7 7 | 14 1 | 7 7 | 14 -----------+----------------------+---------- Total | 14 14 | 28 . . tabulate cc tv if pickone_class==1 Classroom | curriculum | Television (TV) (CC) | 0 1 | Total -----------+----------------------+---------- 0 | 34 36 | 70 1 | 34 31 | 65 -----------+----------------------+---------- Total | 68 67 | 135 . . tabulate cc tv Classroom | curriculum | Television (TV) (CC) | 0 1 | Total -----------+----------------------+---------- 0 | 421 416 | 837 1 | 380 383 | 763 -----------+----------------------+---------- Total | 801 799 | 1,600 . . . * P11.1.2 Summarising the response and predictor variables . . histogram postthks, discrete frequency normal addlabels saving(P11_1_2a, repl > ace) (start=0, width=1) (file P11_1_2a.gph saved) . . table cc tv, contents(mean postthks) format(%4.3f) ------------------------ Classroom | Television curriculu | (TV) m (CC) | 0 1 ----------+------------- 0 | 2.361 2.538 1 | 2.968 2.822 ------------------------ . . table cc tv, contents(mean prethks) format(%4.3f) ------------------------ Classroom | Television curriculu | (TV) m (CC) | 0 1 ----------+------------- 0 | 2.152 2.087 1 | 2.050 1.979 ------------------------ . . generate condition = 1 + cc + 2*tv . . tabulate condition condition | Freq. Percent Cum. ------------+----------------------------------- 1 | 421 26.31 26.31 2 | 380 23.75 50.06 3 | 416 26.00 76.06 4 | 383 23.94 100.00 ------------+----------------------------------- Total | 1,600 100.00 . . label define condition 1 "Neither" 2 "CC only" 3 "TV only" 4 "CC and TV" . . label values condition condition . . tabulate condition condition | Freq. Percent Cum. ------------+----------------------------------- Neither | 421 26.31 26.31 CC only | 380 23.75 50.06 TV only | 416 26.00 76.06 CC and TV | 383 23.94 100.00 ------------+----------------------------------- Total | 1,600 100.00 . . graph bar (mean) prethks postthks, over(condition) saving(P11_1_2b, replace) (file P11_1_2b.gph saved) . . graph bar (mean) prethks postthks, over(condition) /// > blabel(total, format(%4.3f)) /// > ytitle("THKS score") /// > legend(order(1 "Baseline" 2 "Postintervention")) saving(P11_1_2c, rep > lace) (file P11_1_2c.gph saved) . end of do-file