Skip to content
svgsynth-gap

Synthetic control gaps

Did the treated unit diverge from its synthetic control more than placebo units did?

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

How to read it

  1. Read the coloured line as the treated unit's gap from its synthetic control.
  2. Grey lines are placebo units: what gaps happen by chance.
  3. A real effect drops outside the grey after the intervention.
  1. Callout 1: The intervention.
  2. Callout 2: The treated unit diverges from the placebos.
  3. Callout 3: Before: a small gap means a good match.

Watch out

  • A poor pre-period fit undermines the comparison: check pre-period gaps first.

Defaults

Intervention time
0
When the treatment began.
Range -10,000,000,000,000 to 10,000,000,000,000, step 1
Mark the intervention
On
Draw a vertical line at the intervention.
Drop placebos with pre-RMSPE > k × treated (0 = keep all)
5
Hide placebo units that fit poorly before treatment, since they tell you little.
Range 0 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.
  • RMSPE is computed from the gaps as sent: pre-period t < intervention, post-period t ≥ intervention; the p-value is the treated unit's rank of post/pre RMSPE among the units shown divided by their number (Abadie, Diamond & Hainmueller 2010).
  • Placebos whose pre-period fit is poor (pre-RMSPE above k times the treated unit's; k = 5 in the original study) are dropped from the display and the rank.
# Synthetic control gaps — Codesplash Chart Lab (recipe "synth-gap")
# controls: intervention=0, show_intervention=true, max_pre=5
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("synth-gap-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["state"] = pd.Categorical(df["state"].astype("string"), categories=["California", "State 01", "State 02", "State 03", "State 04", "State 05", "State 06", "State 07", "State 08", "State 09", "State 10", "State 11", "State 12", "State 13", "State 14", "State 15", "State 16", "State 17", "State 18", "State 19", "State 20", "State 21", "State 22", "State 23", "State 24", "State 25", "State 26", "State 27", "State 28", "State 29", "State 30"])

_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")
T = "years since program"
GAP = "gap in packs per capita"
UNIT = "state"
TR = "treated"
INTERVENTION = 0
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axhline(0, color="grey", linewidth=0.8)
for unit, d in df.dropna(subset=[T, GAP]).sort_values(T).groupby(UNIT, observed=True):
    treated = bool(d[TR].astype(bool).any())
    ax.plot(d[T], d[GAP], color=PALETTE[0] if treated else "grey", alpha=1 if treated else 0.35, linewidth=2.4 if treated else 1, label=f"{unit} (treated)" if treated else None, zorder=3 if treated else 1)
if INTERVENTION is not None:
    ax.axvline(INTERVENTION, color=REF, linestyle="--", linewidth=1)
ax.set_xlabel(T)
ax.set_ylabel(GAP)
ax.legend(fontsize=8)
plt.show()

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