Multilevel Models in Stata: HLM for Education Research
A practical guide to multilevel/HLM models in Stata using the mixed command. Students nested in schools. Patients nested in hospitals. Here's how.
Education data is inherently hierarchical: students are nested in classrooms, classrooms in schools, schools in districts. Ignoring this nesting inflates your effective sample size and produces standard errors that are too small.
Multilevel models (HLM, mixed-effects models) explicitly model the nesting structure. This guide covers the mixed command in Stata.
Random Intercept Model
Each school has its own intercept, drawn from a distribution.
An ICC of 0.20 means 20% of variance is between schools. If ICC > 0.05, you need a multilevel model.
Random Slope Model
The effect of SES on test scores might differ across schools:
Stop fighting with syntax.
Sytra is an AI research assistant built specifically for statistical computing. No more copy-pasting code into ChatGPT.
Get Early AccessThree-Level Models
Model Comparison
BLUPs: Predicted Random Effects
Common Mistakes
- Using
xtreg, reinstead ofmixed: xtreg is a special case (random intercept only). For random slopes, use mixed. - Too many random effects: Each requires a variance component. Start simple.
- Ignoring convergence warnings: If mixed reports non-convergence, results are meaningless.