reghdfe in Stata: High-Dimensional Fixed Effects Made Simple
reghdfe absorbs any number of fixed effects without creating dummy variables. Here's the full tutorial โ install, syntax, absorb(), cluster(), and singleton handling.
Your fixed-effects model is too big for naive dummy coding, and runtime spikes every time you add another FE dimension.
You will run efficient high-dimensional FE models with diagnostics that keep inference credible.
All examples tested in Stata 18 SE. Compatible with Stata 15+.
Quick Answer
- Install reghdfe from SSC and verify version.
- Specify FE dimensions in absorb(), not manual dummies.
- Cluster at the correct design level and check singleton drops.
- Store model metadata for replication packages.
Estimate High-Dimensional FE Models with Transparent Diagnostics
Set up and run core reghdfe specifications
reghdfe absorbs fixed effects efficiently without explicit dummy expansion. This keeps memory use manageable in large panel settings.
A minimal robust workflow includes installation check, core model, and clustered standard errors.
If you are extending this pipeline, also review How to Merge Datasets in Stata and How to Structure a Stata Project.
1clear all2set obs 40003gen firm_id = ceil(_n/20)4gen worker_id = _n5gen year = 2010 + mod(_n,10)6gen education = 8 + floor(runiform()*10)7gen tenure = floor(runiform()*15)8gen wage = 9 + 0.7*education + 0.3*tenure + rnormal(0,2)910capture which reghdfe11if _rc ssc install reghdfe1213reghdfe wage education tenure, absorb(firm_id year) vce(cluster firm_id)HDFE Linear regression Number of obs = 4,000
Absorbing 2 HDFE groups F( 2, 199) = 412.67
Statistics robust to heteroskedasticity Prob > F = 0.0000
R-squared = 0.6914
Adj R-squared = 0.6751
------------------------------------------------------------------------------
wage | Coefficient std. err. t P>|t|
-------------+----------------------------------------
education | .7041182 .0281304 25.03 0.000
tenure | .2977448 .0189211 15.74 0.000
------------------------------------------------------------------------------Track singleton drops and model support
High-dimensional FE designs can silently lose support if many groups have little within variation. Singleton diagnostics should be part of every run log.
Comparing sample counts across specifications helps catch unintentional design changes.
1clear all2set obs 40003gen firm_id = ceil(_n/20)4gen worker_id = _n5gen year = 2010 + mod(_n,10)6gen education = 8 + floor(runiform()*10)7gen tenure = floor(runiform()*15)8gen wage = 9 + 0.7*education + 0.3*tenure + rnormal(0,2)910capture which reghdfe11if _rc ssc install reghdfe1213reghdfe wage education tenure, absorb(firm_id year) vce(cluster firm_id)1415* ---- Section-specific continuation ----16reghdfe wage education tenure, absorb(firm_id year) vce(cluster firm_id)1718* Compare retained sample19count20estimates store hdfe_main2122reghdfe wage education tenure, absorb(firm_id worker_id year) vce(cluster firm_id)23count24estimates store hdfe_plus_worker2526estimates table hdfe_main hdfe_plus_worker, b se-------------------------------------------------
Variable | hdfe_main hdfe_plus_worker
-------------+-----------------------------------
education | 0.7041 0.6874
| (0.0281) (0.0318)
tenure | 0.2977 0.2812
| (0.0189) (0.0204)
-------------------------------------------------Common Errors and Fixes
"command reghdfe is unrecognized"
reghdfe is user-written and missing from the current ado path.
Install reghdfe and dependencies via SSC, then verify with which reghdfe.
command reghdfe is unrecognized r(199);
reghdfe wage education, absorb(firm_id year)ssc install reghdfewhich reghdfereghdfe wage education, absorb(firm_id year)1capture which reghdfe2if _rc {3 ssc install reghdfe4 ssc install ftools5}6which reghdfec:adoplus eghdfe.ado *! version 6.1.3
Command Reference
xtreg (official FE baseline)
Stata docs โOfficial fixed-effects estimator in Stata and a baseline comparison for reghdfe workflows.
feWithin estimator with unit fixed effectsvce(cluster id)Cluster-robust variance estimatorreRandom-effects alternative for comparison testshausmanCompares FE and RE assumptionsHow Sytra Handles This
Sytra can map research design text into absorb and cluster options, and flag singleton and weak-support issues automatically.
A direct natural-language prompt for this exact workflow:
Run a reghdfe wage model with absorb(firm_id year), cluster by firm_id, report singleton drops, compare with a richer absorb set including worker_id, and output side-by-side coefficient table.Sytra catches these errors before you run.
Sytra can map research design text into absorb and cluster options, and flag singleton and weak-support issues automatically.
Join the Waitlist โFAQ
When should I use reghdfe instead of xtreg?
Use reghdfe when you need multiple high-dimensional fixed effects, faster absorption, or complex clustering structures.
What are singleton observations in reghdfe?
Singletons are observations that are the only record in a fixed-effect group after absorption. reghdfe may drop them to avoid biased inference.
Do I always cluster with reghdfe?
In most panel applications yes, cluster at the treatment or sampling variation level. Report and justify your clustering unit explicitly.
Related Guides
- Panel Data in Stata: xtreg vs. reghdfe vs. areg
- Singleton Observations in Stata reghdfe: What They Are and What to Do
- Clustered Standard Errors in Stata: vce(cluster) Explained with Examples
- Difference-in-Differences in Stata: A Complete Guide
- Explore the regression pillar page
- Open the full regression guide index
- Browse all Stata & R guides on the blog index
- Browse all Stata pillars
We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.