/* Do-file for the Encyclopedia entry: Rabe-Hesketh, S. and Skrondal, A. (2010). Generalized linear mixed models. Penelope Peterson, Eva Baker, Barry McGaw (Eds.), International Encyclopedia of Education (Third Edition). Oxford: Elsevier, volume 7, pp. 171-177. See: http://www.elsevierdirect.com/brochures/educ/PDF/Generalized_Linear_Mixed_Models.pdf See also: http://www.gllamm.orf */ /* Data preparation */ insheet using pisaUSA2000.txt, clear * make variable names math the encyclopedia entry rename female fem summ isei generate ses = (isei - r(mean))/20 /* mean-centered and dividec by 20 */ rename high_school hs rename college coll rename test_lang eng rename pass_read prof * school mean ses egen mn_ses = mean(ses), by(id_school) /* fit the model for Table 1 (using 8-point adaptive quadrature) */ *xtlogit prof fem isei mn_isei hs coll eng, i(id_school) /* gives same result as gllamm */ gllamm prof mn_ses fem ses hs coll eng, i(id_school) link(logit) family(binom) adapt * display odds ratios: gllamm, eform /* graph for Figure 1 */ * set covariates to values for which we would like to make predictions replace fem=0 replace ses = 0 replace hs = 1 replace coll = 0 * make two rows of data for each student, one with * eng=0 and one with eng=1 replace eng = 0 by id_school, sort: generate id_student = _n expand 2 if id_student==1 by id_school (id_student), sort: replace id_student=0 if _n==1 replace eng = 1 if id_student==1 * marginal probabilities (this works only if last estimation command was gllamm) gllapred margp, mu marg fsample * median probabilities (set random intercept, u1, to zero) gen u1 =0 gllapred condp, mu fsample us(u) twoway /// (line margp mn_ses if id_student==0, sort lpatt(solid) lcol(black)) /// (line condp mn_ses if id_student==0, sort lpatt(solid) lcol(black) ) /// (line condp mn_ses if id_student==1, sort lpat(dash) lcol(black)) /// (line margp mn_ses if id_student==1, sort lpat(dash) lcol(black)), /// xtitle(School mean SES) ytitle(Probability of proficiency) /// legend(order(1 "not English" 3 "English")) /// xlabel(,format(%3.1f)) ylabel(,format(%2.1f)) exit