Skip to content

Commit 33ca749

Browse files
authored
Merge pull request #258 from igerber/impuation-tutorial-edits
Update ImputationDiD tutorial to show pretrends=True event study
2 parents dc277e3 + 1e941a9 commit 33ca749

1 file changed

Lines changed: 4 additions & 25 deletions

File tree

docs/tutorials/11_imputation_did.ipynb

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,14 @@
6969
{
7070
"cell_type": "markdown",
7171
"metadata": {},
72-
"source": [
73-
"## Event Study\n",
74-
"\n",
75-
"Event study aggregation estimates treatment effects at each relative time horizon, enabling visualization of dynamic treatment effects and pre-trend assessment."
76-
]
72+
"source": "## Event Study with Pre-Trend Diagnostics\n\nEvent study aggregation estimates treatment effects at each relative time horizon. Setting `pretrends=True` adds **pre-period coefficients** (negative horizons) to the event study, enabling a diagnostic check of the parallel trends assumption.\n\nUnder parallel trends, pre-period coefficients should cluster around zero — indicating no differential trends before treatment. The reference period (h = -1) is normalized to zero by construction."
7773
},
7874
{
7975
"cell_type": "code",
8076
"execution_count": null,
8177
"metadata": {},
8278
"outputs": [],
83-
"source": [
84-
"# Fit with event study aggregation\n",
85-
"est = ImputationDiD()\n",
86-
"results_es = est.fit(data, outcome='outcome', unit='unit', time='period',\n",
87-
" first_treat='first_treat', aggregate='event_study')\n",
88-
"\n",
89-
"# Plot event study\n",
90-
"if HAS_MATPLOTLIB:\n",
91-
" plot_event_study(results_es, title='Imputation DiD Event Study')\n",
92-
"else:\n",
93-
" print(\"Install matplotlib to see visualizations: pip install matplotlib\")"
94-
]
79+
"source": "# Fit with event study aggregation and pre-period coefficients\nest = ImputationDiD(pretrends=True)\nresults_es = est.fit(data, outcome='outcome', unit='unit', time='period',\n first_treat='first_treat', aggregate='event_study')\n\n# Plot event study — pre-period region is automatically shaded\nif HAS_MATPLOTLIB:\n plot_event_study(results_es, title='Imputation DiD Event Study (with Pre-Trends)')\nelse:\n print(\"Install matplotlib to see visualizations: pip install matplotlib\")"
9580
},
9681
{
9782
"cell_type": "code",
@@ -106,13 +91,7 @@
10691
{
10792
"cell_type": "markdown",
10893
"metadata": {},
109-
"source": [
110-
"## Pre-Trend Test\n",
111-
"\n",
112-
"The imputation estimator includes a built-in pre-trend test (Equation 9 in the paper). It tests whether pre-treatment leads are jointly zero using a Wald F-test on untreated observations only.\n",
113-
"\n",
114-
"A key advantage: the pre-trend test is **independent** of the treatment effect estimator (Proposition 9), avoiding the pre-testing problem identified by Roth (2022)."
115-
]
94+
"source": "## Formal Pre-Trend Test\n\nThe event study plot above gives a **visual** diagnostic — do pre-period coefficients look close to zero? For a **statistical** check, `pretrend_test()` runs a Wald F-test on whether all pre-treatment leads are jointly zero (Equation 9 in the paper). This complements the plot: the eye spots patterns, the F-test quantifies evidence consistent with parallel trends.\n\nNote: `pretrend_test()` does not require `pretrends=True` — it runs its own internal lead regression on untreated observations, independent of the treatment effect estimator (Proposition 9). This avoids the pre-testing problem identified by Roth (2022)."
11695
},
11796
{
11897
"cell_type": "code",
@@ -256,4 +235,4 @@
256235
},
257236
"nbformat": 4,
258237
"nbformat_minor": 4
259-
}
238+
}

0 commit comments

Comments
 (0)