diff_diff.RegressionDiscontinuity#
- class diff_diff.RegressionDiscontinuity[source]#
Bases:
objectRegression discontinuity estimator - sharp and fuzzy, with optional covariate adjustment (rdrobust 4.0.0 parity).
SHARP (default): treatment is defined by the running variable crossing a known cutoff (
running >= cutofftreated, matching rdrobust: units exactly at the cutoff are treated). FUZZY: pass the observed take-up column viafit(..., treatment_col=...)- the estimand becomes the local Wald ratio (complier LATE at the cutoff for binary take-up under monotonicity; theestimandresults field says which reading applies) and the results gain a first-stage block. COVARIATE ADJUSTMENT: passfit(..., covariates=[...])(R’scovs=) for the CCFT 2019 additive common-coefficient adjustment - the estimand is UNCHANGED (precision only; requires covariate balance at the cutoff, see the module docstring), bandwidths become covariate-aware, and collinear columns are dropped with a warning undercovs_drop=True. Point estimation uses kernel-weighted local polynomials of orderpon each side; inference is robust bias-corrected per Calonico, Cattaneo & Titiunik (2014). Defaults reproducerdrobust(y, x)/rdrobust(y, x, fuzzy=t)/rdrobust(y, x, covs=Z):p=1,q=2, triangular kernel,bwselect="mserd", nearest-neighbor variance with 3 matches,masspoints="adjust",covs_drop=True.- Parameters:
cutoff (float, default 0.0) – The known threshold
cof the running variable.p (int, default 1) – Local-polynomial order for point estimation; integer in 0..20 (mirroring rdrobust’s accepted surface;
p=0is the local-constant fit).q (int or None, default None) – Order for the bias regression; an explicit
qmust satisfyp < q <= 20.Noneresolves top + 1WITHOUT re-validation, exactly as R does (rdrobust.R:53-57) - sop=20with the defaultqyieldsq=21in both implementations while an explicitq=21is rejected.kernel (str, default "triangular") – “triangular”, “epanechnikov”, or “uniform” (R spellings “tri”/”epa”/”uni” accepted).
bwselect (str, default "mserd") – Data-driven bandwidth selector; one of the 10 rdrobust options (mserd, msetwo, msesum, msecomb1, msecomb2, cerrd, certwo, cersum, cercomb1, cercomb2). Ignored when
his supplied.h (float or None) – Manual main / bias bandwidths (both sides).
halone impliesb = h;hwithrhoimpliesb = h/rho(overriding a suppliedb, as in R);bwithouthis ignored with a warning (R ignores it silently - documented deviation).b (float or None) – Manual main / bias bandwidths (both sides).
halone impliesb = h;hwithrhoimpliesb = h/rho(overriding a suppliedb, as in R);bwithouthis ignored with a warning (R ignores it silently - documented deviation).rho (float or None) – Bandwidth ratio
h/b. Withouth, applies to the SELECTED bandwidths (b = h_selected/rho), mirroring rdrobust.vcov_type (str, default "nn") – Variance estimator. Only “nn” (same-side nearest-neighbor, rdrobust’s default) is implemented in this release; “hc0”-“hc3” and cluster modes raise
NotImplementedError.nnmatch (int, default 3) – Minimum number of nearest neighbors for the NN variance.
masspoints (str, default "adjust") – Mass-point handling: “adjust” (rdrobust default), “check”, “off”.
bwcheck (int or None, default None) – Minimum unique support points forced inside the bandwidth window.
bwrestrict (bool, default True) – Clamp bandwidths to the running variable’s observed range.
scaleregul (float, default 1.0) – Scale of the IK-style regularization in bandwidth selection (0 removes it).
sharpbw (bool, default False) – Fuzzy fits only (
fit(..., treatment_col=...)): when True, bandwidths are selected for the SHARP reduced-form estimator on the outcome (rdrobust’s “approach 1”) instead of the default fuzzy-ratio objective. Automatically in effect - regardless of this flag - under one-sided perfect compliance (zero take-up variance on either side), exactly as in R. On sharp fits the flag has no effect and a warning is emitted (R ignores it silently - documented deviation). Never drops covariates from selection - withcovariatesit selects on the covariate-adjusted sharp objective, as in R.covs_drop (bool, default True) – Covariate-adjusted fits only (
fit(..., covariates=[...])): when True (R’s default), redundant (collinear) covariate columns are dropped with a warning naming them before fitting, and the covariate projection uses a pseudo-inverse; when False the solve is strict and collinear covariates raise a clear error. Withoutcovariatesthe flag has no effect and setting it to False emits a warning (same pattern assharpbwon sharp fits).alpha (float, default 0.05) – Significance level (rdrobust
level = 100*(1-alpha)).
Examples
>>> rd = RegressionDiscontinuity(cutoff=0.0) >>> results = rd.fit(df, outcome_col="y", running_col="x") >>> results.att, results.conf_int # robust bias-corrected inference >>> fuzzy = rd.fit(df, "y", "x", treatment_col="takeup") # fuzzy RD >>> fuzzy.att, fuzzy.first_stage # local Wald ratio + take-up jump
Methods
__init__([cutoff, p, q, kernel, bwselect, ...])fit(data, outcome_col, running_col[, ...])Estimate the RD effect at the cutoff (sharp or fuzzy, optionally covariate-adjusted).
get_params([deep])Return raw constructor parameters (sklearn-compatible).
set_params(**params)Transactionally update parameters (validate before mutating).
- __init__(cutoff=0.0, p=1, q=None, kernel='triangular', bwselect='mserd', h=None, b=None, rho=None, vcov_type='nn', nnmatch=3, masspoints='adjust', bwcheck=None, bwrestrict=True, scaleregul=1.0, sharpbw=False, covs_drop=True, alpha=0.05)[source]#
- classmethod __new__(*args, **kwargs)#