Skip to content
svgevent-study

Event study

Were treated and control units on parallel paths before treatment, and how did the effect evolve after?

Demo data · seed 20261101 · 24 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read points left of zero: before treatment. They should hover around zero.
  2. Read points right of zero: the effect at each period after.
  3. Check the intervals: do pre-period intervals stay away from zero?
  1. Callout 1: Pre-period: flat around zero supports parallel trends.
  2. Callout 2: The reference period.
  3. Callout 3: The effect grows after treatment.

Watch out

  • Flat pre-trends don't prove parallel trends would have continued; test sensitivity.

Defaults

Reference (omitted) period
-1
Send null when the design has no omitted period.
Range -50 to 50, step 1

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • The reference period is drawn hollow at 0 (its coefficient is normalized away); the dashed line marks treatment onset half a period after it.
  • Pre-period coefficients near zero support (but cannot prove) parallel trends; the engine reports the joint pre-trend test and HonestDiD bounds separately.
  • Several estimators or cohorts are dodged horizontally so their intervals do not overlap.
# Event study — Codesplash Chart Lab (recipe "event-study")
# controls: reference=-1
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("event-study-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["estimator"] = pd.Categorical(df["estimator"].astype("string"), categories=["TWFE", "Callaway–Sant'Anna"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
T = "years relative to adoption"
EST = "effect on employment (pp)"
LO = "ci_low"
HI = "ci_high"
G = "estimator"
REFERENCE = -1  # omitted period, drawn hollow at 0
groups = levels_of(df[G]) if G else [None]
series = []
for name in groups:
    d = df if name is None else df[df[G].astype(str) == str(name)]
    series.append((name if name is not None else "", d.dropna(subset=[T]).sort_values(T)))
fig, ax = plt.subplots(figsize=(8, 4.5))
onset = (REFERENCE if REFERENCE is not None else -1) + 0.5
ax.axvspan(df[T].min() - 0.6, onset, color="grey", alpha=0.06, lw=0)
ax.axhline(0, color="grey", linewidth=0.8)
ax.axvline(onset, color=REF, linestyle="--", linewidth=1)
k = len(series)
for i, (name, d) in enumerate(series):
    off = (i - (k - 1) / 2) * 0.16 if k > 1 else 0
    col = PALETTE[i % len(PALETTE)]
    ax.errorbar(d[T] + off, d[EST], yerr=[d[EST] - d[LO], d[HI] - d[EST]], fmt="o-", color=col, ms=5, lw=1, elinewidth=1.6, label=name or None)
    if REFERENCE is not None and not (d[T] == REFERENCE).any():
        ax.plot([REFERENCE + off], [0], "o", mfc="white", mec=col, ms=6)
ax.set_xlabel(T)
ax.set_ylabel(EST)
if G: ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads event-study-demo.csv · app theme from the optional codesplash helper