Panel Data in Stata: xtreg vs. reghdfe vs. areg
When to use xtreg, areg, or reghdfe for panel data in Stata. Includes speed benchmarks, syntax comparison, and common mistakes.
If you work with panel data in Stata, you have three main commands for fixed effects estimation: xtreg, areg, and reghdfe. They all produce the same point estimates for one-way FE. But they differ — sometimes dramatically — in speed, flexibility, what they report, and how they handle edge cases.
This guide tells you when to use which, and warns you about the mistakes that burn hours of debugging time.
The Three Commands at a Glance
| Feature | xtreg, fe | areg | reghdfe |
|---|---|---|---|
| Built-in | Yes | Yes | No (ssc install) |
| Multi-way FE | 1 dimension | 1 dimension | Unlimited |
| Cluster SEs | vce(cluster) | vce(cluster) | vce(cluster), multi-way |
| Singletons | Keeps | Keeps | Drops |
| Speed (large N) | Moderate | Slow | Fast |
| FE reported | sigma_u, rho | No | No |
| Hausman test | Yes | No | No |
xtreg, fe — The Official Panel Command
xtreg, fe is Stata’s native panel fixed effects command. Its main advantage: it reports panel-specific diagnostics like sigma_u (between-group variance), sigma_e (within-group variance), and rho (the fraction of variance due to the fixed effect). It also supports the Hausman test for fixed vs. random effects.
Use xtreg when: You need one-way FE with panel diagnostics (sigma_u, rho), or you want to run a Hausman test, or you need random effects (xtreg, re).
Don’t use xtreg when: You need two-way fixed effects (unit + time), or you have a large dataset and need speed, or you want to absorb multiple high-dimensional FE.
areg — The Absorb Command
areg absorbs one set of fixed effects. It’s essentially regress with a large set of indicator variables, but Stata handles the demeaning internally instead of creating thousands of dummy variables. The coefficients are identical to what you’d get from regress y x1 x2 i.firm.
Honestly? There’s very little reason to use areg in 2026. reghdfe does everything areg does, faster, with multi-way FE and proper singleton handling. The only reason to use areg is if you can’t install community packages.
Stop fighting with syntax.
Sytra is an AI research assistant built specifically for statistical computing. No more copy-pasting code into ChatGPT.
Get Early Accessreghdfe — The Modern Standard
reghdfe (by Sergio Correia) is the de facto standard for fixed effects estimation in applied economics. It uses an iterative demeaning algorithm (based on the ftools package) that’s dramatically faster than computing FE through dummy variables.
Speed comparison
On a dataset of 1 million observations with firm (50,000 groups) and year (20 groups) fixed effects:
That 15x speed difference compounds: robustness checks with 10 specifications × 5 subsamples = 50 regressions. With xtreg, that’s 37 minutes. With reghdfe, it’s 2.5 minutes.
The singleton issue
A singleton is an observation that is the only member of its FE group (e.g., a firm with only one year of data). Singletons don’t contribute to identification in a FE model — they’re perfectly explained by their own FE. But xtreg and areg keep them, which inflates the degrees of freedom and can affect F-statistics and standard errors.
reghdfe automatically detects and drops singletons, with a warning message telling you how many were dropped. This is the correct behavior.
Common Mistakes
- Forgetting
xtsetbeforextreg:xtregrequires you to declare the panel structure withxtset panelvar timevar.reghdfedoes not — it absorbs whatever you specify. - Including FE variables as regressors: If you write
reghdfe y x i.firm, absorb(firm), you’re including firm effects twice. The regression will run but the FE estimates are meaningless. - Clustering at the wrong level: In a panel with firm-year observations, clustering at the firm level accounts for serial correlation within firms. Clustering at the year level accounts for cross-sectional correlation. The choice matters. Default to the panel dimension (firm), but consider two-way clustering (
vce(cluster firm year)) for large panels. - Using
fewithout testing: Fixed effects is not always appropriate. The Hausman test (available withxtreg) checks whether FE and RE give significantly different coefficients. If they don’t differ, random effects is more efficient.
TL;DR — The Decision Tree
- Need one-way FE + Hausman test? →
xtreg, fe - Need multi-way FE? →
reghdfe - Need speed with large data? →
reghdfe - Need random effects? →
xtreg, re - Can’t install packages? →
areg - Everything else? →
reghdfe
When in doubt, use reghdfe. It’s faster, more flexible, handles singletons correctly, and its syntax is cleaner. The only thing it doesn’t do is the Hausman test — and if you need that, run xtreg first, then switch to reghdfe for your main specification.