# Chapter 30: Regression Discontinuity
# Fundamentals of Python for Financial Econometrics - Regression Discontinuity
# Dataset: Ceteris Lab teaching sample

# Chapter 30: Regression Discontinuity
# **Economic question:** What can a policy cutoff reveal about causal effects near the threshold?
#
# RDD compares units just above and below a threshold where treatment assignment changes discontinuously.

# %% Cell 2
import numpy as np, statsmodels.api as sm
rng=np.random.default_rng(30); x=rng.uniform(-1,1,1000); d=(x>=0).astype(int); y=2+.8*x+2*d+rng.normal(0,.5,1000)
mask=np.abs(x)<=.35; X=sm.add_constant(np.c_[x[mask],d[mask],x[mask]*d[mask]])
print(sm.OLS(y[mask],X).fit().params)

# 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.
