Note This MLwiN macro carries out some basic multilevel modeling Note for the examples in Chapter 14 of Note Tom A.B. Snijders & Roel J. Bosker, Note "Multilevel Analysis: An Introduction to Basic and Advanced Multilevel Modeling, Note second edition. London etc.: Sage Publishers, 2012 Note Read spss file combineusa-999_c.sav Note by the "open worksheet" dialog and then selecting file type spss. Note For an unknown reason, the identifiers StIDStd and SCHOOLID start counting at 0 Note instead of one. Therefore we start by adding 1. calc c1 = c1+1 calc c2 = c2+1 miss -999 resp "METASUM" iden 1 "StIDStd" iden 2 "SCHOOLID" expl 1 "cons" setv 1 "cons" setv 2 "cons" pref 0 post 0 Note empty model expl 1 "cons" setv 1 "cons" setv 2 "cons" batch 1 maxi 100 tole 3 start fixe rand like note multilevel data manipulations mlco "SCHOOLID" c26 mlav "SCHOOLID" "ESCS" c28 mlsum "SCHOOLID" "W_FSTUWT" c29 calc c30 = "W_FSTUWT"*c26/c29 sum "W_FSCHWT" b1 calc c31 = 5233*"W_FSCHWT"/b1 note Recode immigration status to ordered categories: 1-2-3 recoded to 0-2-1. note In new coding, 0 = native; 1 = second generation; 2 = first generation. dumm "IMMIG" c41-c43 calc c29 = 2*c42 + c43 mlav "SCHOOLID" c29 c27 name c26 "npup" c27 "sch_imm" c28 "sch_escs" name c29 "imm" c30 "w1ij" c31 "w2j" note w1ij is student-level weight, w2j is school level weight. calc c32 = sqrt("SCHSIZE") Note There is one outlier: calc c33 = ("SCHSIZE" > 6000) name c32 "rootsize" c33 "bigschool" calc c34 = "ST01Q01" - 10 name c34 "grade" calc c7 = c7-16 cton c6 name c6 "sex" calc c6 = c6-1 note code now is: 0 = F, 1 = M. note Age now is centered at 16 years, grade at 10. cton c19 calc c19 = c19-1 name c19 "private" expl 1 "sex" "AGE" "grade" "imm" "ESCS" "private" "sch_imm" "sch_escs" next fixe rand like Note recode urbanisation tabu 0 c20 dumm c20 c35-c39 name c35 "village" c36 "smalltown" c37 "town" c38 "city" c39 "largecity" expl 1 c35 c36 c37 c39 note reference category city next fixe rand like Note saved as PISA_a.wsz Note omit private schools: omit 1 c19 c1-c39 c19 c1-c39 note control for school size expl 1 c32 c33 Note saved as PISA_b.wsz Note omit big school: omit 1 c33 c1-c39 c33 c1-c39 Note saved as PISA_c.wsz Note Back to PISA_a.wsz Note center rootsize at 35 calc "rootsize" = "rootsize" - 35 Note calculate dummy variables for strata, which have strange values: ranks c3 c44 calc c51 = (c44 <= 366.5) calc c60 = c44 + 10000*c51 calc c52 = (c60 <= 1364.5) calc c60 = c60 + 10000*c52 calc c53 = (c60 <= 2884.5) calc c60 = c60 + 10000*c53 calc c54 = (c60 <= 4323.5) note check calc c61 = c51+c52+c53+c54 note this is always 1, OK. expl 1 c52-54