diff_diff.RegressionDiscontinuity#

class diff_diff.RegressionDiscontinuity[source]#

Bases: object

Regression 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 >= cutoff treated, matching rdrobust: units exactly at the cutoff are treated). FUZZY: pass the observed take-up column via fit(..., treatment_col=...) - the estimand becomes the local Wald ratio (complier LATE at the cutoff for binary take-up under monotonicity; the estimand results field says which reading applies) and the results gain a first-stage block. COVARIATE ADJUSTMENT: pass fit(..., covariates=[...]) (R’s covs=) 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 under covs_drop=True. Point estimation uses kernel-weighted local polynomials of order p on each side; inference is robust bias-corrected per Calonico, Cattaneo & Titiunik (2014). Defaults reproduce rdrobust(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 c of the running variable.

  • p (int, default 1) – Local-polynomial order for point estimation; integer in 0..20 (mirroring rdrobust’s accepted surface; p=0 is the local-constant fit).

  • q (int or None, default None) – Order for the bias regression; an explicit q must satisfy p < q <= 20. None resolves to p + 1 WITHOUT re-validation, exactly as R does (rdrobust.R:53-57) - so p=20 with the default q yields q=21 in both implementations while an explicit q=21 is 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 h is supplied.

  • h (float or None) – Manual main / bias bandwidths (both sides). h alone implies b = h; h with rho implies b = h/rho (overriding a supplied b, as in R); b without h is ignored with a warning (R ignores it silently - documented deviation).

  • b (float or None) – Manual main / bias bandwidths (both sides). h alone implies b = h; h with rho implies b = h/rho (overriding a supplied b, as in R); b without h is ignored with a warning (R ignores it silently - documented deviation).

  • rho (float or None) – Bandwidth ratio h/b. Without h, 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 - with covariates it 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. Without covariates the flag has no effect and setting it to False emits a warning (same pattern as sharpbw on 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]#
Parameters:
classmethod __new__(*args, **kwargs)#