# Chapter 31: Synthetic Control and Comparative Case Studies
# Fundamentals of Python for Financial Econometrics - Synthetic Control and Comparative Case Studies
# Dataset: Ceteris Lab teaching sample

# Chapter 31: Synthetic Control and Comparative Case Studies
# **Economic question:** How can one treated region be compared with a data-driven combination of untreated regions?
#
# Synthetic control constructs a transparent counterfactual from weighted comparison units chosen to reproduce the treated unit before intervention.

# %% Cell 2
import numpy as np
rng=np.random.default_rng(31); T=20; donors=np.vstack([10+.2*np.arange(T)+rng.normal(0,.3,T) for _ in range(4)])
synth=donors.mean(axis=0); treated=synth+rng.normal(0,.15,T); treated[12:]+=2.5
print('average post-treatment gap', (treated[12:]-synth[12:]).mean())

# Interpretation checklist
# - State the unit of observation and units of every variable.
# - Separate association, prediction, and causation.
# - Report magnitude and uncertainty.
# - Identify the most important threat to validity.
