Upper-undergraduate econometrics

Difference-in-Differences

A two-group, two-period panel notebook for treatment effects, common trends, and what happens when parallel trends fail.

Econometrics Panel data Advanced EasyEcon / Marimo Regression, identification, and simulated evidence
Focus

Parallel trends, group means, and treatment-effect decomposition

Adjust treatment effects, group gaps, noise, and trend violations to see exactly when the DiD estimate matches the truth and when it drifts.

What to explore

Change parameters and watch the model adjust.

  • True treatment effect, baseline group gap, common trend, trend violation, noise, and cell size
  • The panel is simulated with a fixed seed so treatment and bias move predictably

Core ideas

Interpret the mechanics before you chase the graphs.

  • Difference-in-differences works by netting out a common change that both groups would have shared.
  • A treated-group-specific trend shock looks like extra treatment if the model cannot separate it.
  • The four group-time means tell the identification story before any algebra does.

Learning goals

What this model should help students internalize.

  • Construct the DiD estimate from treated and control group means across pre and post periods.
  • Interpret the parallel-trends assumption as the key identifying restriction.
  • See how trend violations contaminate the treatment estimate.

Prerequisites

Concepts to review before diving in.

  • Simple regression intuition
  • Comfort with group means and before-after comparisons

EasyEcon interactive

DiD notebook

EasyEcon / Marimo

On phones, the full-screen view gives the cleanest notebook reading experience.

Open full screen

Deferred notebook load

Parallel trends, group means, and treatment-effect decomposition

Adjust treatment effects, group gaps, noise, and trend violations to see exactly when the DiD estimate matches the truth and when it drifts.

Open full screen
The EasyEcon Marimo/WASM bundle loads only when requested or when the panel scrolls near view on fast connections.

Next models to study

Keep moving through the track.