Methodology
2026-04-039 min read

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.

Sytra Team
Research Engineering Team, Sytra AI

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.

* Students nested in schools
mixed test_score ses parental_educ || school:
 
* Compute the ICC
estat icc

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:

mixed test_score ses parental_educ || school: ses, covariance(unstructured)

Stop fighting with syntax.

Sytra is an AI research assistant built specifically for statistical computing. No more copy-pasting code into ChatGPT.

Get Early Access

Three-Level Models

* Students in classrooms in schools
mixed test_score ses teacher_exp || school: || classroom:

Model Comparison

quietly mixed test_score ses || school:
estimates store ri
quietly regress test_score ses
estimates store ols
lrtest ri ols

BLUPs: Predicted Random Effects

mixed test_score ses || school:
predict u_school, reffects
predict u_se, reses
serrbar u_school u_se rank, scale(1.96) yline(0)

Common Mistakes

  • Using xtreg, re instead of mixed: 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.
#Multilevel#Stata#Education#Public Health

Enjoyed this article?