pyrdd provides estimation and inference procedures for regression discontinuity
designs (RDD). It is a refactor of the excellent
rdrobust with a focus on performance,
compatibility and maintainability.
Note
pyrdd is tested for correctness against rdrobust but still in early development
and its API is subject to change.
- performance:
pyrddis orders of magnitudes faster thanrdrobust - compatibility:
pyrddhas minimal dependencies and is compatible withnumpy >= 2.0 - maintainability:
pyrddis tested againstrdrobust, uses modern Python tooling and is fully type-checked
Estimate a sharp RD with automatic bandwidth selection:
import numpy as np
from pyrdd.discontinuity import fit
from pyrdd.bandwidth import select_bandwidth
# Create sample data
rng = np.random.default_rng(0)
x = rng.uniform(-1, 1, 500) # running variable
y = (x >= 0) + 0.5 * x + rng.normal(size=500) # outcome with jump at 0
# Estimate RDD with robust bias-corrected inference and MSE optimal bandwidth
result = fit(y=y, x=x, c=0.0, bwselect="mserd")
# Inspect results
print(result.robust.coefficient) # bias-corrected estimate
print(result.conventional.coefficient) # conventional estimate
print(result.robust.standard_error) # robust standard error
# It is also possible to estimate optimal bandwidth independently
bandwidth = select_bandwidth(y=y, x=x, c=0.0, bwselect="mserd")
print(bandwidth.h) # main bandwidth (left, right)