Skip to main content

rdlocal

Regression discontinuity (RD) estimation in plain NumPy/SciPy/pandas, BSD-3-Clause.

  • rd_estimate: sharp and fuzzy RD, local polynomial of order p, kernels triangular / epanechnikov / uniform, conventional and bias-corrected estimates, conventional and robust SEs, CIs and p-values (Calonico-Cattaneo-Titiunik 2014), HC0-HC3, nearest-neighbour and cluster-robust variances.
  • rd_bandwidth: MSE-optimal common (mserd) and side-specific (msetwo) bandwidths (CCFT 2019 supplement, Section 12), msesum, the comb1/comb2 combinations, their CER versions (cerrd, certwo, cersum, cercomb1/2; CCFT 2017 sec. 2.3), and Imbens-Kalyanaraman (ik, 2012).
  • rd_density_test: local polynomial density manipulation test (Cattaneo-Jansson-Ma 2020).
  • rd_binned: evenly spaced or quantile-spaced binned means for RD plots.

All functions return frozen dataclasses with a JSON-friendly to_dict().

import numpy as np
from rdlocal import rd_estimate, rd_density_test, rd_binned

rng = np.random.default_rng(0)
x = rng.uniform(-1, 1, 2000)
y = 0.5 * x + 0.4 * (x >= 0) + rng.normal(0, 0.3, 2000)

r = rd_estimate(y, x, cutoff=0.0)            # p=1, triangular, mserd, hc1
print(r.coef, r.coef_bc, r.ci_robust, r.h_left, r.n_left, r.n_right)
fz = rd_estimate(y, x, fuzzy=(x >= 0).astype(float))
print(rd_density_test(x).p_value)
print(rd_binned(y, x, nbins=20).to_dict()["y_mean"][:3])

Treatment is x >= cutoff. Non-finite rows are dropped. With cluster=... the vce argument is ignored.

Validation

pytest runs the fast suite; pytest -m slow runs the Monte Carlo coverage check. At a fixed bandwidth with a uniform kernel the sharp estimate equals plain OLS on each side (1e-10). Against rdrobust/rddensity, run only as black boxes (inputs and numbers in tests/data, see tests/make_reference.py), estimates, SEs and bias-corrected density values agree to ~1e-9 or better at the same bandwidths; bandwidth h given b agrees to <=1%; the full selector agrees to 1% on 14 of 56 tested cells and ~1% on the Senate default (the d-pilot of Section 12.2 is not recoverable, see CLEANROOM.md) (see CLEANROOM.md, deviations, and the measured gaps in the test docstrings).

Published examples: the CCFT (2017) Senate output (pp.392-393, 400) is encoded in tests/test_published_senate.py, which skips with an explanatory message unless you supply the Senate vote-margin data (not shipped). With the data it reproduces p.393 (7.4253, SE 1.4954, robust CI [4.06975, 10.9833], N 343/310). The CER scaling and combination structure of the published table are checked without the data. Simulation designs of CCT (2014) supplement S.3.1 provide the other checks.

Roadmap (out of scope for 0.1.0)

Covariate adjustment (CCFT 2019), multiple cutoffs/scores, kink designs, McCrary (2008) test, restricted density model and jackknife SE, CER arg-min bandwidth, local randomisation / power tools.

Methodology

docs/METHODOLOGY.md explains the statistics (local polynomial RD, bandwidth selection, robust bias-corrected inference, manipulation testing), how the package was built, and the validation evidence, including the reproduced US Senate results and the one open problem.

Contributing

Bug reports and research-based contributions are welcome. See CONTRIBUTING.md for setup, testing, and the clean-room rules.

Provenance

An independent clean-room implementation written from the papers listed in CLEANROOM.md. It is not affiliated with, endorsed by, or derived from the authors' rdpackages software.

Citations

  • Calonico, Cattaneo, Titiunik (2014), Econometrica 82(6): 2295-2326.
  • Calonico, Cattaneo, Farrell (2020), Econometrics Journal 23(2): 192-210.
  • Calonico, Cattaneo, Farrell, Titiunik (2019), Review of Economics and Statistics 101(3): 442-451.
  • Cattaneo, Jansson, Ma (2020), Journal of the American Statistical Association 115(531): 1449-1455.
  • Cattaneo, Jansson, Ma (2018), Stata Journal 18(1): 234-261.
  • Imbens, Kalyanaraman (2012), Review of Economic Studies 79(3): 933-959.

Metadata

Release files for rdlocal 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rdlocal 0.1.0
File Size Uploaded Provenance Actions
rdlocal-0.1.0.tar.gz 178.4 kB With provenance Details for rdlocal-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rdlocal 0.1.0
File Interpreter ABI Platform Actions
rdlocal-0.1.0-py3-none-any.whl Python 3 none any Details for rdlocal-0.1.0-py3-none-any.whl

Total release size: 197.9 kB

Release files / rdlocal-0.1.0.tar.gz

Download URL rdlocal-0.1.0.tar.gz
Size 178.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8806dc62b31803910c98dbac996484a1b03359c7b92011bb70ee34d9ca19a42b
BLAKE2b-256 checksum
How to use checksums
4d96ddbc7ec2997be565171d1aa189200c675a1cd07faa39669bc9e6dee2d5c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / rdlocal-0.1.0-py3-none-any.whl

Download URL rdlocal-0.1.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65c801862cd3b03e5becfc7caeef8ec1b6f02c1ff62783f125cfec5f5ae197b4
BLAKE2b-256 checksum
How to use checksums
42021ad44aa7a50643416cdc95ed71cd02de54c59d877d3f614f8ea93a6900ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for rdlocal 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rdlocal-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page