------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\12.1.smcl log type: smcl opened on: 27 Mar 2020, 18:22:36 . **************************************************************************** . * Module 12: Cross-Classified Models - Stata Practical . * . * P12.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/ . **************************************************************************** . . * P12.1.1 Exploring the cross-classified data structure . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/12.1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/12.1.dta obs: 2,310 vars: 13 2 Aug 2013 17:08 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- schid byte %8.0g School ID neighid int %8.0g Neighbourhood ID studid int %9.0g Student ID attain float %3.2f Attainment (age 16) cons byte %9.0g Constant p7vrq float %3.2f Verbal reasoning (age 12) p7read float %3.2f Reading (age 12) dadocc float %3.2f Father's occupation dadunemp byte %8.0g Father unemployed daded byte %8.0g Father stayed in school beyond 15 momed byte %8.0g Mother stayed in school beyond 15 male byte %8.0g Male deprive float %3.2f Neighbourhood deprivation ------------------------------------------------------------------------------- Sorted by: . . summarize Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- schid | 2,310 10.00866 6.269943 0 20 neighid | 2,310 495.3398 267.4553 26 1098 studid | 2,310 1155.5 666.9839 1 2310 attain | 2,310 .0933957 1.002091 -1.3276 2.4151 cons | 2,310 1 0 1 1 -------------+--------------------------------------------------------- p7vrq | 2,310 .5057663 10.64822 -27.028 42.972 p7read | 2,310 -.0443549 13.88751 -31.866 28.134 dadocc | 2,310 -.464169 11.78157 -23.454 29.226 dadunemp | 2,310 .1090909 .3118207 0 1 daded | 2,310 .2151515 .4110164 0 1 -------------+--------------------------------------------------------- momed | 2,310 .2484848 .432228 0 1 male | 2,310 .4800866 .4997115 0 1 deprive | 2,310 .0216658 .6218811 -1.082 2.959 . . list schid neighid studid attain in 1/10 +-----------------------------------+ | schid neighid studid attain | |-----------------------------------| 1. | 0 675 1 0.74 | 2. | 0 647 2 0.26 | 3. | 0 650 3 -1.33 | 4. | 0 650 4 0.74 | 5. | 0 648 5 -0.13 | |-----------------------------------| 6. | 0 648 6 0.56 | 7. | 0 665 7 -0.36 | 8. | 0 661 8 0.74 | 9. | 0 675 9 -0.36 | 10. | 0 664 10 0.91 | +-----------------------------------+ . . codebook schid neighid ------------------------------------------------------------------------------- schid School ID ------------------------------------------------------------------------------- type: numeric (byte) range: [0,20] units: 1 unique values: 17 missing .: 0/2,310 mean: 10.0087 std. dev: 6.26994 percentiles: 10% 25% 50% 75% 90% 2 5 9 16 19 ------------------------------------------------------------------------------- neighid Neighbourhood ID ------------------------------------------------------------------------------- type: numeric (int) range: [26,1098] units: 1 unique values: 524 missing .: 0/2,310 mean: 495.34 std. dev: 267.455 percentiles: 10% 25% 50% 75% 90% 143.5 240 530 707 808 . . table neighid schid if inrange(neighid,1,38) | inrange(neighid,251,263) /// > | inrange(neighid,793,803) ---------------------------------------------------------------------- Neighbour | School ID hood ID | 2 3 8 10 15 16 17 18 19 20 ----------+----------------------------------------------------------- 26 | 5 27 | 1 29 | 1 8 30 | 2 31 | 1 1 32 | 1 5 33 | 2 2 35 | 3 36 | 2 37 | 1 38 | 1 4 251 | 4 1 252 | 1 3 1 253 | 3 256 | 2 258 | 5 259 | 6 1 2 260 | 7 261 | 4 3 262 | 5 1 1 263 | 14 1 1 793 | 1 7 794 | 1 1 12 795 | 1 1 796 | 9 797 | 4 1 798 | 9 1 799 | 1 1 800 | 2 801 | 1 1 803 | 4 ---------------------------------------------------------------------- . . egen pickone_school = tag(schid) . . egen pickone_neigh = tag(neighid) . . egen pickone_comb = tag(neighid schid) . . bysort schid: egen numneighs = total(pickone_comb) . . tabulate numneighs if pickone_school==1 numneighs | Freq. Percent Cum. ------------+----------------------------------- 11 | 1 5.88 5.88 29 | 1 5.88 11.76 31 | 1 5.88 17.65 37 | 1 5.88 23.53 40 | 1 5.88 29.41 41 | 1 5.88 35.29 42 | 2 11.76 47.06 43 | 1 5.88 52.94 46 | 1 5.88 58.82 47 | 1 5.88 64.71 52 | 2 11.76 76.47 53 | 1 5.88 82.35 61 | 1 5.88 88.24 65 | 1 5.88 94.12 92 | 1 5.88 100.00 ------------+----------------------------------- Total | 17 100.00 . . bysort neighid: egen numschools = total(pickone_comb) . . tabulate numschools if pickone_neigh==1 numschools | Freq. Percent Cum. ------------+----------------------------------- 1 | 309 58.97 58.97 2 | 176 33.59 92.56 3 | 33 6.30 98.85 4 | 6 1.15 100.00 ------------+----------------------------------- Total | 524 100.00 . . bysort schid: generate schoolsize = _N . . summarize schoolsize if pickone_school==1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- schoolsize | 17 135.8824 55.23912 22 286 . . bysort neighid: generate neighsize = _N . . summarize neighsize if pickone_neigh==1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- neighsize | 524 4.408397 2.785033 1 16 . . summarize neighsize if pickone_neigh==1, detail neighsize ------------------------------------------------------------- Percentiles Smallest 1% 1 1 5% 1 1 10% 1 1 Obs 524 25% 2 1 Sum of Wgt. 524 50% 4 Mean 4.408397 Largest Std. Dev. 2.785033 75% 6 14 90% 8 14 Variance 7.756411 95% 10 14 Skewness 1.010207 99% 13 16 Kurtosis 4.038365 . . . . * P12.1.2 Summarising the response and predictor variables . . tabstat attain p7vrq p7read male dadocc daded momed dadunemp, /// > stat(mean sd) columns(stat) format(%4.3f) variable | mean sd -------------+-------------------- attain | 0.093 1.002 p7vrq | 0.506 10.648 p7read | -0.044 13.888 male | 0.480 0.500 dadocc | -0.464 11.782 daded | 0.215 0.411 momed | 0.248 0.432 dadunemp | 0.109 0.312 ---------------------------------- . . . summarize deprive if pickone_neigh==1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- deprive | 524 .0371489 .621928 -1.082 2.959 . . spikeplot attain, ylabel(0(100)500) . end of do-file