Estimation¶
- rd_stream.rd_estimate(fml, data, *, cutoff=0.0, polynomial_order=1, bias_order=None, derivative=0, kernel='triangular', bandwidth='mserd', bias_bandwidth=None, bandwidth_ratio=None, vcov='nearest_neighbor', n_neighbors=3, weights=None, mass_points='adjust', min_distinct=None, restrict_bandwidth=True, standardize=True, regularization=1.0, scale=1.0, treatment=None, sharp_bandwidth=False, covariates=None, donut=None, donut_closed='none', memory='auto', max_memory_gb=None, memory_reserve=None, workdir=None, n_threads=None, profile=False)[source]¶
Sharp regression discontinuity: local-polynomial estimates at the cutoff with robust bias-corrected inference (Calonico, Cattaneo and Titiunik 2014), as R’s rdrobust 4.1.1 computes them.
The data are sorted once by the running variable. Every bandwidth step and the final fit are then compiled, threaded passes over the observations within that step’s bandwidth. With several outcomes (
"y1 + y2 ~ x"), or several bandwidths (a list), all the fits share that one sort.- Parameters:
fml (str) –
"y ~ x": the outcome and the running variable. Several outcomes:"y1 + y2 + y3 ~ x".data (str, path, polars.DataFrame or polars.LazyFrame) – A Parquet file or glob, or a frame.
cutoff (float, default 0) – Observations with x >= cutoff are treated.
polynomial_order (int, default 1) – The order p of the local polynomial (rdrobust’s
p).bias_order (int, optional) – The order q of the bias-correction polynomial; default p + 1 (rdrobust’s
q).derivative (int, default 0) – The derivative at the cutoff to estimate: 1 for a regression kink design (rdrobust’s
deriv).kernel ({"triangular", "epanechnikov", "uniform"})
bandwidth (str, float, (left, right) pair, or list of them) – A selector (
"mserd", the default, or"msetwo","msesum","msecomb1","msecomb2","cerrd","certwo","cersum","cercomb1","cercomb2": rdrobust’sbwselect), or the main bandwidth h itself (rdrobust’sh). A list fits each bandwidth in turn, from one sort, and returns anRDMulti.bias_bandwidth (float or (left, right) pair, optional) – The bias bandwidth b with a given h (rdrobust’s
b); default h, or h / bandwidth_ratio.bandwidth_ratio (float, optional) – rdrobust’s
rho: b = h / rho.vcov (str or dict, default "nearest_neighbor") – The variance estimator (rdrobust’s
vce), spelled as in hdfe-stream: “nearest_neighbor”, “HC0”, “HC1” (or “hetero”), “HC2” or “HC3”, or clustered by a column as{"CRV1": "school"}(or"CRV1:school"),{"CRV2": ...}(Bell and McCaffrey’s bias-reduced linearization) or{"CRV3": ...}(the jackknife-like correction). The names are case-insensitive. The clustered variances are rdrobust’s: CRV1 is rdrobust’s CR1 (hdfe-stream’s CRV1 factor, G/(G-1) (N-1)/(N-k)), and CRV2 and CRV3 take no small-sample factor, as in rdrobust (hdfe-stream’s CRV3 takes CRV1’s).n_neighbors (int, default 3) – Neighbors for the nearest-neighbor variance (rdrobust’s
nnmatch).weights (str, optional) – Sampling weights, multiplying the kernel weights.
mass_points ({"adjust", "check", "off"}) – rdrobust’s
masspoints. With “adjust” (the default), when 20% or more of the observations on either side share a value of the running variable with another one, the pilot bandwidth counts distinct values and every bandwidth covers at least 10 of them.min_distinct (int, optional) – Every bandwidth covers at least this many distinct values on each side (rdrobust’s
bwcheck).restrict_bandwidth (bool, default True) – Bandwidths no wider than the data (rdrobust’s
bwrestrict).standardize (bool, default True) – Select bandwidths on x and y divided by their standard deviations (rdrobust’s
stdvars).regularization (float, default 1) – The scale of the bandwidth selectors’ regularization term (rdrobust’s
scaleregul).scale (float, default 1) – Multiplies the estimate (rdrobust’s
scalepar).treatment (str, optional) – The treatment take-up, for a fuzzy design (rdrobust’s
fuzzy): the estimate is the ratio of the jumps in the outcome and in the take-up (a local Wald estimator), and the result has the first stage.sharp_bandwidth (bool, default False) – In a fuzzy design, select the bandwidths for the outcome’s jump alone (rdrobust’s
sharpbw). Always so when take-up does not vary on one side of the cutoff.covariates (str or list of str, optional) – Covariates for the adjustment of Calonico, Cattaneo, Farrell and Titiunik (2019) (rdrobust’s
covs): they enter linearly with the same coefficients on both sides, which leaves the estimand unchanged when they are balanced at the cutoff and can shorten the intervals. Collinear covariates are dropped with a warning.donut (float, (left, right) pair, or list of them, optional) – A donut hole (Cattaneo, Idrobo and Titiunik 2020, section 5.4): the observations within this distance of the cutoff are left out, and the whole fit, bandwidth selection included, runs on the rest. The hole is the interval (cutoff - donut_left, cutoff + donut_right), which holds x = cutoff, so a positive right radius drops it. A list gives one fit per radius, from one read (0 for no hole), labeled
[donut=...].donut_closed ({"none", "left", "right", "both"}, default "none") – Whether the hole’s ends belong to it, as Polars’
closed: “none” keeps the observations exactly at the radius (|x - cutoff| >= donut, as Cattaneo, Idrobo and Titiunik do); “left”, “right” or “both” also drops those at cutoff - donut_left, at cutoff + donut_right, or at both. It matters for a discrete running variable. A radius of 0 drops nothing on its side.memory ({"auto", "rows", "by_value", "window"}) – How the data are held. “rows” reads and sorts the rows used, and fits on every row. “by_value” groups the rows by the value of the running variable as it reads them (one streaming pass), keeping only each value’s count, sums and cross-products, and fits on one row per value, which gives the same results; memory grows with the number of distinct values rather than the rows, and the fit needs no clusters or weights. “window” takes the full sample’s statistics in streaming passes (standard deviations, exact quartiles and distinct counts, and the power sums of rdbwselect’s fit over each side’s range) and holds only the rows near the cutoff; when a step’s window does not fit in memory, the rows are written to
workdirin slabs by distance from the cutoff, and each window sum reads them a slab at a time. It takes any fit, and gives the same results as “rows”. “auto” (the default) groups by value when the fit allows it and the running variable has at most half as many distinct values as rows (an approximate count, in one pass over it), else holds the rows when they fit the memory budget, and otherwise takes the window path.max_memory_gb (float, optional) – The memory the fit may use (stream-limits’
MemoryBudget); default the machine’s or the job’s limit. When even a slab of rows does not fit, the fit stops with a MemoryError.memory_reserve (float, optional) – The share of
max_memory_gbkept back for what the model of the fit’s memory does not cover; default 0.15.workdir (str, optional) – Where the window path writes its slabs (a run directory, removed after the fit); default $HDFE_STREAM_WORKDIR, else the system temporary directory. The slabs take about 8 bytes a row for each column the fit reads.
n_threads (int, optional) – Threads for the compiled passes (stream-limits’
thread_scope); default all.profile (bool, default False) – Return hdfe-stream’s
Profileof the fit instead of fitting: the rows and distinct values of the running variable (one streaming pass), the pathmemorywould take, and its memory and disk. For the window path, its summary passes run too.
- Returns:
RDResult, or RDMulti with several outcomes or bandwidths; a Profile with
profile=True.
References
Calonico, S., Cattaneo, M. D. and Titiunik, R. (2014). Robust nonparametric confidence intervals for regression-discontinuity designs. Econometrica 82(6), 2295-2326.
Cattaneo, M. D., Idrobo, N. and Titiunik, R. (2020). A Practical Introduction to Regression Discontinuity Designs: Foundations. Cambridge Elements: Quantitative and Computational Methods for Social Science. Cambridge University Press. https://doi.org/10.1017/9781108684606
- rd_stream.rd_bandwidth(fml, data, *, cutoff=0.0, selector='mserd', all_selectors=False, polynomial_order=1, bias_order=None, derivative=0, kernel='triangular', vcov='nearest_neighbor', n_neighbors=3, weights=None, mass_points='adjust', min_distinct=None, restrict_bandwidth=True, standardize=True, regularization=1.0, treatment=None, sharp_bandwidth=False, covariates=None, donut=None, donut_closed='none', memory='auto', max_memory_gb=None, memory_reserve=None, workdir=None, n_threads=None, profile=False)[source]¶
Data-driven bandwidths, as R’s rdbwselect computes them (all ten selectors with
all_selectors=True). The options arerd_estimate’s;donuttakes one radius or (left, right) pair here.
- rd_stream.rd_placebo(fml, data, placebo_cutoffs, *, cutoff=0.0, include_cutoff=True, bandwidth='mserd', bias_bandwidth=None, bandwidth_ratio=None, polynomial_order=1, bias_order=None, derivative=0, kernel='triangular', vcov='nearest_neighbor', n_neighbors=3, weights=None, mass_points='adjust', min_distinct=None, restrict_bandwidth=True, standardize=True, regularization=1.0, scale=1.0, treatment=None, sharp_bandwidth=False, covariates=None, memory='auto', max_memory_gb=None, memory_reserve=None, workdir=None, n_threads=None)[source]¶
RD estimates at placebo cutoffs, where the outcome should not jump.
A placebo cutoff below
cutoffis fitted on the observations below it only, and one above on those above it only (x >= cutoff), so that the true discontinuity cannot leak into a placebo estimate, as Cattaneo, Idrobo and Titiunik (2020, section 5.3) recommend. Each fit selects its own bandwidth unless one is given. Withinclude_cutoff, the estimate at the true cutoff, on every observation, is included too.- Parameters:
fml (str) –
"y ~ x", or several outcomes as"y1 + y2 ~ x".data (str, path, polars.DataFrame or polars.LazyFrame)
placebo_cutoffs (list of float) – The placebo cutoffs; none may equal
cutoff. A cutoff too near the edge of its side’s observations (or with too few distinct values between) has no estimate, and the table’snotesays why.cutoff (float, default 0) – The true cutoff.
include_cutoff (bool, default True) – Also estimate at the true cutoff.
bandwidth (str or float or (left, right) pair, default "mserd") – A selector, with which each cutoff’s fit selects its own bandwidth, or a number (or left/right pair), which every fit then shares.
rd_estimate's. (The other options are)
- Returns:
PlaceboResult – Its
tablehas one row per outcome and cutoff;plot()draws the estimates and their robust intervals against the cutoff.
References
Cattaneo, M. D., Idrobo, N. and Titiunik, R. (2020). A Practical Introduction to Regression Discontinuity Designs: Foundations. Cambridge Elements: Quantitative and Computational Methods for Social Science. Cambridge University Press. https://doi.org/10.1017/9781108684606