Methodology
2026-02-259 min read

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.

Sytra Team
Research Engineering Team, Sytra AI

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

Featurextreg, fearegreghdfe
Built-inYesYesNo (ssc install)
Multi-way FE1 dimension1 dimensionUnlimited
Cluster SEsvce(cluster)vce(cluster)vce(cluster), multi-way
SingletonsKeepsKeepsDrops
Speed (large N)ModerateSlowFast
FE reportedsigma_u, rhoNoNo
Hausman testYesNoNo

xtreg, fe — The Official Panel Command

* Must declare panel structure first
xtset firm year
 
* Fixed effects estimation
xtreg y x1 x2, fe vce(cluster firm)

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 y x1 x2, absorb(firm) vce(cluster firm)

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 Access

reghdfe — The Modern Standard

* Two-way fixed effects (the common case)
reghdfe y x1 x2, absorb(firm year) vce(cluster firm)
 
* Three-way fixed effects
reghdfe y x1 x2, absorb(firm year industry) vce(cluster firm year)
 
* Installation
ssc install reghdfe, replace
ssc install ftools, replace

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:

xtreg, fe (+ i.year)
~45 seconds
areg absorb(firm) (+ i.year)
~60 seconds
reghdfe absorb(firm year)
~3 seconds

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 xtset before xtreg: xtreg requires you to declare the panel structure with xtset panelvar timevar. reghdfe does 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 fe without testing: Fixed effects is not always appropriate. The Hausman test (available with xtreg) 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.

#Panel Data#Fixed Effects#Stata#Economics

Enjoyed this article?