note This is a MLn macro for testing level-one heteroscedasticity note using test (10.5) of Snijders & Bosker (2011), note which is also test (9.6) in Bryk & Raudenbush (2002). note The requirement for using this test is that a two-level model note has been specified where all variables that have a random effect note at level two also have a fixed effect. note To get the groupwise degrees of freedom right, note it is necessary that all explanatory variables with fixed effects note are level-one variables. note The box B20 must be set to a positive value: note this is the lowest value for the degrees of freedom note (df_j in Snijders & Bosker) that is required note to include a level-two unit (j) in the calculation. note The advised value is B20 = 10. note The macro uses (i.e., overwrites) columns C201-C212 note and boxes B11-B20 in the worksheet. note It produces the following (see notation in Snijders & Bosker, 2011, Section 10.4.1): note For the level-two units with df_j equal to or larger than B20, note C201 is the unit identifier, C202 = df_j, C203 = s_j^2, C214 = d_j. note Further B11 = H, B12 = N'-1, B13 = associated p-value. echo 0 calc B13 = sign(b20) switch B13 case 1: leave case: say Default is used: B20 = 10. \n calc b20 = 10 leave endswitch calc B13 = sign(b20 - 10) case -1: say The chi-squared null distribution of this test is not reliable \n say for B20 less than 10. \n leave endswitch note Put groupwise OLS predictions in c201. olse 2 c201 note Put column number of level-2 identifier in b16. idco 2 b16 note Put number of parameters with fixed effects in b18. nfixe b18 note Put column number of dependent variable in b19. yvar b19 note Put squared residuals in c202 and their groupwise sums in c203. calc c202 = (c201 - cb19)*(c201 - cb19) note Put df_j in c204 and residual SSE in c203. mlsum cb16 c202 c203 mlco cb16 c204 calc c204 = c204 - b18 note Drop groups with df_j < B20 calc b20 = b20 - 1 omit -1000 b20 c204 c203 cb16 c204 c203 c205 calc b20 = b20 + 1 note Calculate residual MSE within groups. calc c206 = c203/c204 note Reduce to one copy per group: c212 = group identifier, c207 = df_j, c208 = s_j^2. take c205 c204 c206 c212 c207 c208 note Calculate B17 = ls_tot. calc c209 = loge(c208) calc c210 = c209*c207 sum c210 B14 sum c207 B15 divi B14 B15 B17 note Calculate d_j (normal deviates). calc c211 = (sqrt(0.5*c207))*(c209 - B17) calc c213 = c211*c211 sum c213 B11 count c213 B12 calc B12 = B12 - 1 cpro B11 B12 B13 note Clean up. calc C201 = C212 calc C202 = C207 calc C203 = C208 calc C204 = C211 erase C205-C213 echo 1 note Heteroscedasticity test note For the level-two units with df_j equal to or larger than B20, note C201 is the unit identifier, note C202 = d.f., note C203 = within-group residual standard deviation, note C204 = normalized within-group standard deviation note Test statistic H, degrees of freedom, p-value: write B11 B12 B13 note plot of normalized within-group standard deviation against within-group d.f.: plot c204 c202