Panel data · Difference-in-differences
Two-Way Fixed Effects
Two-way fixed effects compare changes within units after removing common time shocks.
Removing unit and time averages
The two-way fixed-effects model gives each unit and each date its own intercept:
The coefficient uses variation left after removing unit means and time means (Wooldridge, 2010). For a balanced panel, the transformed regressor is
A demeaning table
| Unit and time | $x_{it}$ | Unit mean | Time mean | Grand mean | $\widetilde x_{it}$ |
|---|---|---|---|---|---|
| A, 1 | 2 | 3 | 3 | 4 | 0 |
| A, 2 | 4 | 3 | 5 | 4 | 0 |
| B, 1 | 4 | 5 | 3 | 4 | 0 |
| B, 2 | 6 | 5 | 5 | 4 | 0 |
This example has no usable two-way within variation. A regressor that only adds unit and time components cannot identify $\beta$.
Assumptions and interpretation
Strict exogeneity requires current errors to have zero conditional mean given the full regressor history and fixed effects. Identification also requires variation after both effects are removed.
The coefficient describes a weighted within-unit association after common time shocks. Causal interpretation needs a design that supports the exogeneity condition.
Implementation issues
Dummy-variable and absorption algorithms should give the same coefficient. They can count parameters differently for finite-sample covariance corrections. Standard errors should follow the error dependence, often through unit clustering.
The within transformation decomposes the panel matrix into unit means, time means, and a residual matrix.
Interpretation and reporting
The coefficient uses regressor variation that remains after both sets of effects are removed. In the table, every transformed value is zero. That sample cannot estimate $\beta$, even though raw $x$ varies across cells.
Report the amount of two-way residualized variation, the unit count, the time count, and the covariance estimator. Describe the comparison that supplies identification. A coefficient based on a small set of changing units can have limited population scope.
Unit effects absorb stable differences. Time effects absorb shocks common to all units. Neither set removes unit-specific time-varying confounding. In staggered-treatment settings, one pooled coefficient can also combine heterogeneous cohort-time effects with hard-to-read weights.
Reproducible implementation
Validate unique unit-time observations and define the estimation sample. Residualize both $y$ and $x$ against unit and time indicators. For an unbalanced panel, use an absorption algorithm or explicit indicators instead of the balanced-panel shortcut.
Regress the residualized outcome on the residualized regressor. Compare this coefficient with the full dummy-variable specification. Inspect the residualized regressor for near-zero variation.
Choose covariance from the error dependence, commonly clustering by unit. Match absorbed-parameter counts before comparing software standard errors. Save the sample indicators and fixed-effect dimensions. If treatment timing varies, supplement the pooled model with cohort-time estimates that identify their comparison groups (Wooldridge, 2010).
Further reading
Wooldridge develops fixed-effects estimation and inference for panels (Wooldridge, 2010).
Sources and further reading
- Jeffrey M. Wooldridge. 2010. Econometric Analysis of Cross Section and Panel Data. MIT Press. Source.
About this benchmark task
- Status
- In the benchmark
- Identifier
twoway_fe- Family
- Difference-in-differences
- Software
- Stata, R, Python
- Source
- Benchmark task set
Task statement
Estimate y_twocluster on x with firm and year fixed effects. Report the x coefficient with a standard error clustered on firm as row x.
Required output
x