Glossary
R: Difference-in-Differences with fixed effects
A quasi-experimental research design that estimates a causal effect by comparing changes over time between a treatment group and a control group. The key identifying assumption — the parallel trends assumption — requires that, absent treatment, both groups would have followed ...
title: Difference-in-Differences (DiD)
slug: did
Definition
A quasi-experimental research design that estimates a causal effect by comparing changes over time between a treatment group and a control group. The key identifying assumption — the parallel trends assumption — requires that, absent treatment, both groups would have followed similar trajectories.
Why It Matters
Randomized experiments are often infeasible in economics and public policy. DiD provides a credible path to causal inference by leveraging natural variation in treatment timing across groups. When the parallel trends assumption holds, the design difference-in-differences estimator removes both time-invariant group differences and common time shocks, isolating the treatment effect. Violations of parallel trends, however, produce biased estimates, making pre-trend testing and sensitivity analysis essential.
Example
A state raises its minimum wage while a neighboring state does not. Employment changes in both states are observed before and after the policy. The DiD estimate — the change in employment in the treatment state minus the change in the control state — identifies the causal effect of the minimum wage increase, provided both states would have followed parallel employment trends absent the policy change.
```r
library(fixest)
model <- feols(employment ~ treated * post | state + year, data = df)
```
Related Terms
Software Notes
R: Use fixest for fast twoway fixed-effects DiD; did package for staggered adoption designs with heterogeneous treatment effects (Callaway and Sant'Anna, 2021). Stata: Use reghdfe for twoway FE DiD; csdid for staggered adoption. Python: Use linearmodels for panel DiD; custom implementations for heterogeneous-treatment-effect estimators.
Contact Us for Support → /contact/