twfedec is a Stata command that shows what a two-way fixed effects (TWFE) regression estimates, using the numerical equivalence result in Ishimaru (2026). In a balanced panel, the TWFE coefficient on a treatment equals a weighted average of first-difference (FD) coefficients across all time horizons; with time-varying covariates, an adjustment term is added.
The command reports the pieces of this decomposition:
FD coefficients: The coefficient from regressing k-period changes in the outcome on k-period changes in the treatment, for every horizon k = 1, ..., T-1.
Weights: How much each horizon contributes to the TWFE coefficient. The weights sum to one and reflect how much variation in k-period treatment changes remains after period effects and covariates are accounted for.
Adjustment term: Present only with time-varying covariates. It reflects how differently the TWFE and FD regressions account for covariate effects; a large value signals a violation of time homogeneity.
Reference: Ishimaru, S. (2026). What Do We Get from Two-Way Fixed Effects Regressions? Implications from Numerical Equivalence. The Econometrics Journal, Forthcoming.
Open Stata and install the package with its example dataset:
ssc install twfedec, all
twfedec runs its regressions through reghdfe. If you don't have it yet:
ssc install require
ssc install ftools
ssc install reghdfe
Basic syntax(the data must be xtset):
xtset id year
twfedec y d w, tinvariant(c1 c2) graph
Inputs:
y: outcome variable
d: treatment variable (one)
w: time-varying covariates (optional; one or many)
c1, c2: time-invariant covariates, each given a period-specific coefficient (optional; one or many; e.g., i.region gives region-by-period fixed effects)
graph: draws the FD coefficients, the TWFE coefficient, and the weights (optional)
Unit and period fixed effects are always includes, so don't specify them.
To open the help file with detailed instructions and examples:
help twfedec