Type: Package
Title: Boundary Regression Discontinuity Designs
Version: 0.0.2
URL: https://rdpackages.github.io/rd2d/
Description: Provides estimation and inference procedures for boundary regression discontinuity (RD) designs using local polynomial methods, based on either bivariate coordinates or distance-based approaches. Methods are developed in Cattaneo, Titiunik, and Yu (2025) https://mdcattaneo.github.io/papers/Cattaneo-Titiunik-Yu_2025_BoundaryRD.pdf.
Imports: MASS, expm, ggplot2, stringr
License: GPL-2
Encoding: UTF-8
RoxygenNote: 7.3.2
Maintainer: Ruiqi Rae Yu <rae.yu@princeton.edu>
NeedsCompilation: no
Packaged: 2025-06-10 19:43:09 UTC; yuruiqi
Author: Matias D. Cattaneo [aut], Rocio Titiunik [aut], Ruiqi Rae Yu [aut, cre]
Repository: CRAN
Date/Publication: 2025-06-10 20:00:02 UTC

rd2d: Two Dimensional Local Polynomial Regression Discontinuity Design

Description

This package implements estimation and inference procedures for boundary regression discontinuity (RD) designs using local polynomial methods, based on either bivariate coordinates or distance-based approaches. Methods are developed in Cattaneo, Titiunik, and Yu (2025a). A companion software article is available at Cattaneo, Titiunik, and Yu (2025b).

Included functions are: rd2d for inference and estimation based on bivariate coordinates, rdbw2d for data-driven bandwidth selection based on bivariate coordinates, rd2d.dist for distance-based inference and estimation, rdbw2d.dist for distance-based bandwidth selection.

print() and summary() methods are available all four functions.

Related Stata, R, and Python packages useful for inference in RD designs are described in the following website:

https://rdpackages.github.io/

For an introduction to regression discontinuity design, see Cattaneo, Idrobo, Titiunik (2024) and references therein.

Author(s)

Matias Cattaneo, Princeton University. cattaneo@princeton.edu. Rocio Titiunik, Princeton University. titiunik@princeton.edu. Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu.

References

See Also

Useful links:


Print Method for 2D Local Polynomial RD Estimation

Description

Prints the results of a 2D local polynomial regression discontinuity (RD) estimation, as obtained from rd2d.

Usage

## S3 method for class 'rd2d'
print(x, ...)

Arguments

x

An object of class rd2d, returned by rd2d.

...

Additional arguments passed to the method (currently ignored).

Value

No return value. This function is called for its side effects, which are to print the rd2d results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rd2d for conducting 2D local polynomial RD estimation.

Supported methods: print.rd2d, summary.rd2d.


Print Method for 2D Local Polynomial RD Estimation (Distance-Based)

Description

Prints the results of a 2D local polynomial regression discontinuity (RD) estimation using distance-based evaluation, as obtained from rd2d.dist.

Usage

## S3 method for class 'rd2d.dist'
print(x, ...)

Arguments

x

An object of class rd2d.dist, returned by rd2d.dist.

...

Additional arguments passed to the method (currently ignored).

Value

No return value. This function is called for its side effects: it prints the rd2d.dist results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rd2d.dist for estimation using distance-based methods in 2D local polynomial RD designs.

Supported methods: print.rd2d.dist, summary.rd2d.dist.


Print Method for Bandwidth Selection for 2D Local Polynomial RD Design

Description

The print method for bandwidth selection for 2D local polynomial RD design

Usage

## S3 method for class 'rdbw2d'
print(x, ...)

Arguments

x

Class rdbw2d objects, obtained by calling rdbw2d.

...

Additional arguments passed to the method (currently ignored).

Value

No return value, called to print rdbw2d results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rdbw2d for bandwidth selection for 2D local polynomial RD design

Supported methods: print.rdbw2d, summary.rdbw2d.


Print Method for Bandwidth Selection (Distance-Based) in 2D Local Polynomial RD Design

Description

Print method for displaying summary information from distance-based bandwidth selection in 2D local polynomial regression discontinuity (RD) designs, as produced by rdbw2d.dist.

Usage

## S3 method for class 'rdbw2d.dist'
print(x, ...)

Arguments

x

An object of class rdbw2d.dist, returned by rdbw2d.dist.

...

Additional arguments passed to the method (currently ignored).

Value

No return value. This function is called for its side effects: it prints summary information of rdbw2d.dist.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rdbw2d.dist for distance-based bandwidth selection in 2D local polynomial RD design.

Supported methods: print.rdbw2d.dist, summary.rdbw2d.dist.


Two-Dimensional Local Polynomial Regression Discontinuity Design

Description

rd2d implements bivariate local polynomial boundary regression discontinuity (RD) point estimators with robust bias-corrected pointwise confidence intervals and uniform confidence bands, developed in Cattaneo, Titiunik and Yu (2025a) with a companion software article Cattaneo, Titiunik and Yu (2025b). For robust bias-correction, see Calonico, Cattaneo, Titiunik (2014).

Companion commands are: rdbw2d for data-driven bandwidth selection.

For other packages of RD designs, visit https://rdpackages.github.io/

Usage

rd2d(
  Y,
  X,
  t,
  b,
  h = NULL,
  deriv = c(0, 0),
  tangvec = NULL,
  p = 1,
  q = 2,
  kernel = c("tri", "triangular", "epa", "epanechnikov", "uni", "uniform", "gau",
    "gaussian"),
  kernel_type = c("prod", "rad"),
  vce = c("hc1", "hc0", "hc2", "hc3"),
  masspoints = c("check", "adjust", "off"),
  C = NULL,
  level = 95,
  cbands = TRUE,
  side = c("two", "left", "right"),
  repp = 1000,
  bwselect = c("mserd", "imserd", "msetwo", "imsetwo", "user provided"),
  method = c("dpi", "rot"),
  bwcheck = 50 + p + 1,
  scaleregul = 3,
  scalebiascrct = 1,
  stdvars = TRUE
)

Arguments

Y

Dependent variable; a numeric vector of length N, where N is the sample size.

X

Bivariate running variable (a.k.a score variable); a numeric matrix or data frame of dimension N \times 2, with each row \mathbf{X}_i = (X_{1i}, X_{2i}).

t

Treatment indicator; a logical or binary vector indicating treatment assignment (t_i = 1 if treated, t_i = 0 otherwise).

b

Evaluation points; a matrix or data frame specifying boundary points \mathbf{b}_j = (b_{1j}, b_{2j}), of dimension J \times 2.

h

Bandwidths. Either a positive scalar (same bandwidth for all dimensions and groups), or a matrix/data frame of size J \times 4, corresponding to h_{\text{control},1}, h_{\text{control},2}, h_{\text{treated},1}, h_{\text{treated},2} at each evaluation point. If not specified, bandwidth h is computed by the companion command rdbw2d. Default is h = NULL.

deriv

The order of the derivatives of the regression functions to be estimated; a numeric vector of length 2 specifying the number of derivatives in each coordinate (e.g., c(1,2) corresponds to \partial_1 \partial_2^2).

tangvec

Tangent vectors; a matrix or data frame of dimension J \times 2 specifying directional derivatives. Overrides deriv if provided.

p

Polynomial order for point estimation (p = 1 by default).

q

Polynomial order for robust confidence interval construction. Must satisfy q \geq p; default is q = p + 1.

kernel

Kernel function to use. Options are "unif", "uniform" (uniform), "triag", "triangular" (triangular, default), and "epan", "epanechnikov" (Epanechnikov).

kernel_type

Kernel structure. Either "prod" for product kernels (default) or "rad" for radial kernels.

vce

Variance-covariance estimation method. Options are:

  • "hc0": heteroskedasticity-robust plug-in residual variance estimator without small-sample adjustment.

  • "hc1": heteroskedasticity-robust plug-in residual variance estimator with HC1 small-sample adjustment (default).

  • "hc2": heteroskedasticity-robust plug-in residual variance estimator with HC2 adjustment.

  • "hc3": heteroskedasticity-robust plug-in residual variance estimator with HC3 adjustment.

masspoints

Handling of mass points in the running variable. Options are:

  • "check": detects presence of mass points and reports the number of unique observations (default).

  • "adjust": adjusts preliminary bandwidths to ensure a minimum number of unique observations within each side of the cutoff.

  • "off": ignores presence of mass points.

C

Cluster ID variable used for cluster-robust variance estimation. Default is C = NULL.

level

Nominal confidence level for intervals/bands, between 0 and 100 (default is 95).

cbands

Logical. If TRUE, also compute uniform confidence bands (default is FALSE).

side

Type of confidence interval. Options: "two" (two-sided, default), "left" (left tail), or "right" (right tail).

repp

Number of repetitions for critical value simulation (used in uniform confidence bands). Default is 1000.

bwselect

Bandwidth selection strategy. Options:

  • "mserd". One common MSE-optimal bandwidth selector for the boundary RD treatment effect estimator for each evaluation point (default).

  • "imserd". IMSE-optimal bandwidth selector for the boundary RD treatment effect estimator based on all evaluation points.

  • "msetwo". Two different MSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator for each evaluation point.

  • "imsetwo". Two IMSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator based on all evaluation points.

  • "user provided". User-provided bandwidths. If h is not NULL, then bwselect is overwritten to "user provided".

method

Bandwidth selection method for bias estimator based on local polynomials. Either "dpi" (default) for data-driven plug-in MSE optimal bandwidth selector or "rot" for rule-of-thumb bandwidth selector.

bwcheck

If a positive integer is provided, the preliminary bandwidth used in the calculations is enlarged so that at least bwcheck observations are used. If masspoints == "adjust", ensure at least bwcheck unique observations are used. The program stops with “not enough observations” if sample size N < bwcheck. Default is 50 + p + 1.

scaleregul

Scaling factor for the regularization term in bandwidth selection. Default is 3.

scalebiascrct

Scaling factor used for bias correction based on higher order expansions. Default is 1.

stdvars

Logical. If TRUE, the running variables X_{1i} and X_{2i} are standardized before computing the bandwidths. Default is TRUE. Standardization only affects automatic bandwidth selection if bandwidths are not manually provided via h.

Value

An object of class "rd2d", a list with components:

results

A data frame with point estimates, variances, p-values, confidence intervals, confidence bands, bandwidths and effective sample size at each evaluation point.

b1, b2

First and second coordinate of evaluation points \mathbf{b} = (b_1,b_2).

Est.p

Point estimate \widehat{\tau}_p(\mathbf{b}).

Var.p

Variance of estimate \widehat{\tau}_p(\mathbf{b}).

Est.q

Bias-corrected point estimate \widehat{\tau}_q(\mathbf{b}).

Var.q

Variance of bias-corrected estimate \widehat{\tau}_q(\mathbf{b}).

p-value

P-value based on t-statistic with bias-corrected estimate.

CI.lower, CI.upper

Pointwise confidence intervals.

CB.lower, CB.upper

Uniform confidence bands if computed.

h01, h02, h11, h12

Bandwidths used in each coordinate and group. The four columns correspond to h_{\text{control},1}, h_{\text{control},2}, h_{\text{treated},1}, h_{\text{treated},2} respectively.

Nh0, Nh1

Effective sample size on each side of the cutoff.

results.A0

Same structure as results but for control group outcomes.

results.A1

Same structure as results but for treated group outcomes.

cov.q

Covariance matrix for bias-corrected estimates \widehat{\tau}_q(\mathbf{b}) for all point evaluations \mathbf{b}.

opt

List of options used in the function call.

rdmodel

String label for the RD model.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

References

See Also

rdbw2d, print.rd2d, summary.rd2d

Examples

# Simulated example
set.seed(123)
n <- 5000
X1 <- rnorm(n)
X2 <- rnorm(n)
t <- as.numeric(X1 > 0)
Y <- 3 + 2 * X1 + 1.5 * X2 + t + rnorm(n)
X <- cbind(X1, X2)
b <- matrix(c(0, 0, 0, 1), ncol = 2)

# Estimate treatment effect using rd2d
result <- rd2d(Y, X, t, b, cbands = TRUE)
print(result)
summary(result)

Local Polynomial RD Estimation on Distance-Based Running Variables

Description

rd2d.dist implements distance-based local polynomial boundary regression discontinuity (RD) point estimators with robust bias-corrected pointwise confidence intervals and uniform confidence bands, developed in Cattaneo, Titiunik and Yu (2025a) with a companion software article Cattaneo, Titiunik and Yu (2025b). For robust bias-correction, see Calonico, Cattaneo, Titiunik (2014).

Companion commands are: rdbw2d.dist for data-driven bandwidth selection.

For other packages of RD designs, visit https://rdpackages.github.io/

Usage

rd2d.dist(
  Y,
  D,
  h = NULL,
  b = NULL,
  p = 1,
  q = 2,
  kink = c("off", "on"),
  kernel = c("tri", "triangular", "epa", "epanechnikov", "uni", "uniform", "gau",
    "gaussian"),
  level = 95,
  cbands = TRUE,
  side = c("two", "left", "right"),
  repp = 1000,
  bwselect = c("mserd", "imserd", "msetwo", "imsetwo", "user provided"),
  vce = c("hc1", "hc0", "hc2", "hc3"),
  rbc = c("on", "off"),
  bwcheck = 50 + p + 1,
  masspoints = c("check", "adjust", "off"),
  C = NULL,
  scaleregul = 1,
  cqt = 0.5
)

Arguments

Y

Dependent variable; a numeric vector of length N, where N is the sample size.

D

Distance-based scores \mathbf{D}_i=(\mathbf{D}_{i}(\mathbf{b}_1),\cdots,\mathbf{D}_{i}(\mathbf{b}_J)); dimension is N \times J where N = sample size and J = number of cutoffs; non-negative values means data point in treatment group and negative values means data point in control group.

h

Bandwidth(s); if c=h then same bandwidth is used for both groups; if a matrix of size J \times 2 is provided, each row contains (h_{\text{control}}, h_{\text{tr}}) for the evaluation point; if not specified, bandwidths are selected via rdbw2d.dist().

b

Optional evaluation points; a matrix or data frame specifying boundary points \mathbf{b}_j = (b_{1j}, b_{2j}), dimension J \times 2.

p

Polynomial order for point estimation. Default is p = 1.

q

Polynomial order for bias-corrected estimation. Must satisfy q \geq p. Default is q = p + 1.

kink

Logical; whether to apply kink adjustment. Options: "on" (default) or "off".

kernel

Kernel function to use. Options are "unif", "uniform" (uniform), "triag", "triangular" (triangular, default), and "epan", "epanechnikov" (Epanechnikov).

level

Nominal confidence level for intervals/bands, between 0 and 100 (default is 95).

cbands

Logical. If TRUE, also compute uniform confidence bands (default is FALSE).

side

Type of confidence interval. Options: "two" (two-sided, default), "left" (left tail), or "right" (right tail).

repp

Number of bootstrap repetitions used for critical value simulation. Default is 1000.

bwselect

Bandwidth selection strategy. Options:

  • "mserd". One common MSE-optimal bandwidth selector for the boundary RD treatment effect estimator for each evaluation point (default).

  • "imserd". IMSE-optimal bandwidth selector for the boundary RD treatment effect estimator based on all evaluation points.

  • "msetwo". Two different MSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator for each evaluation point.

  • "imsetwo". Two IMSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator based on all evaluation points.

  • "user provided". User-provided bandwidths. If h is not NULL, then bwselect is overwritten to "user provided".

vce

Variance-covariance estimator for standard errors. Options:

"hc0"

Heteroskedasticity-robust variance estimator without small sample adjustment (White robust).

"hc1"

Heteroskedasticity-robust variance estimator with degrees-of-freedom correction (default).

"hc2"

Heteroskedasticity-robust variance estimator using leverage adjustments.

"hc3"

More conservative heteroskedasticity-robust variance estimator (similar to jackknife correction).

rbc

Logical. Whether to apply robust bias correction. Options: "on" (default) or "off". When kink = off, turn on rbc means setting q to p + 1. When kink = on, turn on rbc means shrinking the bandwidth selector to be proportional to N^{-1/3}.

bwcheck

If a positive integer is provided, the preliminary bandwidth used in the calculations is enlarged so that at least bwcheck observations are used. The program stops with “not enough observations” if sample size N < bwcheck. Default is 50 + p + 1.

masspoints

Strategy for handling mass points in the running variable. Options:

"check"

Check for repeated values and adjust inference if needed (default).

"adjust"

Adjust bandwidths to guarantee a sufficient number of unique support points.

"off"

Ignore mass points completely.

C

Cluster ID variable used for cluster-robust variance estimation. Default is C = NULL.

scaleregul

Scaling factor for the regularization term in bandwidth selection. Default is 1.

cqt

Constant controlling subsample fraction for initial bias estimation. Default is 0.5.

Details

MSE bandwidth selection for geometrical RD design

Value

An object of class "rd2d.dist", a list containing:

results

A data frame with point estimates, variances, p-values, confidence intervals, confidence bands, and bandwidths at each evaluation point.

b1

First coordinate of the evaluation point.

b2

Second coordinate of the evaluation point.

Est.p

Point estimate \widehat{\tau}_{\text{dist},p}(\mathbf{b}) with polynomial order p.

Var.p

Variance of \widehat{\tau}_{\text{dist},p}(\mathbf{b}).

Est.q

Bias-corrected estimate \widehat{\tau}_{\text{dist},q}(\mathbf{b}) with polynomial order q.

Var.q

Variance of \widehat{\tau}_{\text{dist},q}(\mathbf{b}).

pvalue

Two-sided p-value based on T_{\text{dist},q}(\mathbf{b}).

CI.lower

Lower bound of confidence interval.

CI.upper

Upper bound of confidence interval.

CB.lower

Lower bound of uniform confidence band (if cbands=TRUE).

CB.upper

Upper bound of uniform confidence band (if cbands=TRUE).

h0

Bandwidth used for control group (D_i(\mathbf{b}) < 0).

h1

Bandwidth used for treatment group (D_i(\mathbf{b}) \geq 0).

Nh0

Effective sample size for control group.

Nh1

Effective sample size for treatment group.

results.A0

Same structure as results but for control group outcomes.

results.A1

Same structure as results but for treatment group outcomes.

tau.hat

Vector of point estimates \widehat{\tau}_p(\mathbf{b}).

se.hat

Standard errors corresponding to \widehat{\tau}_p(\mathbf{b}).

cb

Confidence intervals and uniform bands.

cov.q

Covariance matrix for bias-corrected estimates \widehat{\tau}_{\text{dist},q}(\mathbf{b}) for all point evaluations \mathbf{b}.

opt

List of options used in the function call.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

References

See Also

rdbw2d.dist, rd2d, print.rd2d.dist, summary.rd2d.dist

Examples

set.seed(123)
n <- 5000

# Generate running variables x1 and x2
x1 <- rnorm(n)
x2 <- rnorm(n)

# Define treatment assignment: treated if x1 >= 0
d <- as.numeric(x1 >= 0)

# Generate outcome variable y with some treatment effect
y <- 3 + 2 * x1 + 1.5 * x2 + 1.5 * d + rnorm(n, sd = 0.5)

# Define evaluation points (e.g., at the origin and another point)
eval <- data.frame(x.1 = c(0, 0), x.2 = c(0, 1))

# Compute Euclidean distances to evaluation points
dist.a <- sqrt((x1 - eval$x.1[1])^2 + (x2 - eval$x.2[1])^2)
dist.b <- sqrt((x1 - eval$x.1[2])^2 + (x2 - eval$x.2[2])^2)

# Combine distances into a matrix
D <- as.data.frame(cbind(dist.a, dist.b))

# Assign positive distances for treatment group, negative for control
d_expanded <- matrix(rep(2 * d - 1, times = ncol(D)), nrow = nrow(D), ncol = ncol(D))
D <- D * d_expanded

# Run the rd2d.dist function
result <- rd2d.dist(y, D, b = eval)

# View the estimation results
print(result)
summary(result)

Bandwidth Selection for 2D Local Polynomial RD Design

Description

rdbw2d implements bandwidth selector for bivariate local polynomial boundary regression discontinuity (RD) point estimators with robust bias-corrected pointwise confidence intervals and uniform confidence bands, developed in Cattaneo, Titiunik and Yu (2025a) with a companion software article Cattaneo, Titiunik and Yu (2025b). For robust bias-correction, see Calonico, Cattaneo, Titiunik (2014).

Companion commands are: rd2d for point estimation and inference procedures.

For other packages of RD designs, visit https://rdpackages.github.io/

Usage

rdbw2d(
  Y,
  X,
  t,
  b,
  p = 1,
  deriv = c(0, 0),
  tangvec = NULL,
  kernel = c("tri", "triangular", "epa", "epanechnikov", "uni", "uniform", "gau",
    "gaussian"),
  kernel_type = c("prod", "rad"),
  bwselect = c("mserd", "imserd", "msetwo", "imsetwo"),
  method = c("dpi", "rot"),
  vce = c("hc1", "hc0", "hc2", "hc3"),
  bwcheck = 50 + p + 1,
  masspoints = c("check", "adjust", "off"),
  C = NULL,
  scaleregul = 1,
  scalebiascrct = 1,
  stdvars = TRUE
)

Arguments

Y

Dependent variable; a numeric vector of length N, where N is the sample size.

X

Bivariate running variable (a.k.a score variable); a numeric matrix or data frame of dimension N \times 2, with each row \mathbf{X}_i = (X_{1i}, X_{2i}).

t

Treatment indicator; a logical or binary vector indicating treatment assignment (t_i = 1 if treated, t_i = 0 otherwise).

b

Evaluation points; a matrix or data frame specifying boundary points \mathbf{b}_j = (b_{1j}, b_{2j}), of dimension J \times 2.

p

Polynomial order of local polynomial estimator.

deriv

The order of the derivatives of the regression functions to be estimated; a numeric vector of length 2 specifying the number of derivatives in each coordinate (e.g., c(1,2) corresponds to \partial_1 \partial_2^2).

tangvec

Tangent vectors; a matrix or data frame of dimension J \times 2 specifying directional derivatives. Overrides deriv if provided.

kernel

Kernel function to use. Options are "unif", "uniform" (uniform), "triag", "triangular" (triangular, default), and "epan", "epanechnikov" (Epanechnikov).

kernel_type

Kernel structure. Either "prod" for product kernels (default) or "rad" for radial kernels.

bwselect

Bandwidth selection strategy. Options:

  • "mserd". One common MSE-optimal bandwidth selector for the boundary RD treatment effect estimator for each evaluation point (default).

  • "imserd". IMSE-optimal bandwidth selector for the boundary RD treatment effect estimator based on all evaluation points.

  • "msetwo". Two different MSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator for each evaluation point.

  • "imsetwo". Two IMSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator based on all evaluation points.

  • "user provided". User-provided bandwidths. If h is not NULL, then bwselect is overwritten to "user provided".

method

Bandwidth selection method for bias estimator based on local polynomials. Either "dpi" (default) for data-driven plug-in MSE optimal bandwidth selector or "rot" for rule-of-thumb bandwidth selector.

vce

Variance-covariance estimation method. Options are:

  • "hc0": heteroskedasticity-robust plug-in residual variance estimator without small-sample adjustment.

  • "hc1": heteroskedasticity-robust plug-in residual variance estimator with HC1 small-sample adjustment (default).

  • "hc2": heteroskedasticity-robust plug-in residual variance estimator with HC2 adjustment.

  • "hc3": heteroskedasticity-robust plug-in residual variance estimator with HC3 adjustment.

bwcheck

If a positive integer is provided, the preliminary bandwidth used in the calculations is enlarged so that at least bwcheck observations are used. If masspoints == "adjust", ensure at least bwcheck unique observations are used. The program stops with “not enough observations” if sample size N < bwcheck. Default is 50 + p + 1.

masspoints

Handling of mass points in the running variable. Options are:

  • "check": detects presence of mass points and reports the number of unique observations (default).

  • "adjust": adjusts preliminary bandwidths to ensure a minimum number of unique observations within each side of the cutoff.

  • "off": ignores presence of mass points.

C

Cluster ID variable used for cluster-robust variance estimation. Default is C = NULL.

scaleregul

Scaling factor for the regularization term in bandwidth selection. Default is 3.

scalebiascrct

Scaling factor used for bias correction based on higher order expansions. Default is 1.

stdvars

Logical. If TRUE, the running variables X_{1i} and X_{2i} are standardized before computing the bandwidths. Default is TRUE. Standardization only affects automatic bandwidth selection if bandwidths are not manually provided via h.

Value

A list of class "rdbw2d" containing:

bws

Data frame of estimated bandwidths for each evaluation point:

b1

First coordinate of the evaluation point.

b2

Second coordinate of the evaluation point.

h01

Estimated bandwidth for X_{1i} in the control group (\mathcal{A}_0).

h02

Estimated bandwidth for X_{2i} in the control group (\mathcal{A}_0).

h11

Estimated bandwidth for X_{1i} in the treatment group (\mathcal{A}_1).

h12

Estimated bandwidth for X_{2i} in the treatment group (\mathcal{A}_1).

mseconsts

Data frame of intermediate quantities used in bandwidth calculation:

Nh0

Effective sample size for the control group \mathcal{A}_0.

Nh1

Effective sample size for the treatment group \mathcal{A}_1.

bias.0

Bias constant estimate for the control group.

bias.1

Bias constant estimate for the treatment group.

var.0

Variance constant estimate for the control group.

var.1

Variance constant estimate for the treatment group.

reg.bias.0

Bias correction adjustment for the control group.

reg.bias.1

Bias correction adjustment for the treatment group.

reg.var.0

Variance of the bias estimate for the control group.

reg.var.1

Variance of the bias estimate for the treatment group.

opt

List containing:

p

Polynomial order used for estimation.

kernel

Kernel function used.

kernel_type

Type of kernel (product or radial).

stdvars

Logical indicating if standardization was applied.

bwselect

Bandwidth selection strategy used.

method

Bandwidth estimation method.

vce

Variance estimation method.

scaleregul

Scaling factor for regularization.

scalebiascrct

Scaling factor for bias correction.

N

Total sample size N.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

References

See Also

rd2d, print.rdbw2d, summary.rdbw2d

Examples

# Simulated example
set.seed(123)
n <- 5000
X1 <- rnorm(n)
X2 <- rnorm(n)
t <- as.numeric(X1 > 0)
Y <- 3 + 2 * X1 + 1.5 * X2 + t + rnorm(n)
X <- cbind(X1, X2)
b <- matrix(c(0, 0, 0, 1), ncol = 2)

# MSE optimal bandwidth for rd2d
bws <- rdbw2d(Y, X, t, b)

# View the bandwidth selection results
print(bws)
summary(bws)

Bandwidth Selection for Distance-Based RD Designs

Description

rdbw2d.dist implements bandwidth selector for distance-based local polynomial boundary regression discontinuity (RD) point estimators with robust bias-corrected pointwise confidence intervals and uniform confidence bands, developed in Cattaneo, Titiunik and Yu (2025a) with a companion software article Cattaneo, Titiunik and Yu (2025b). For robust bias-correction, see Calonico, Cattaneo, Titiunik (2014).

Usage

rdbw2d.dist(
  Y,
  D,
  b = NULL,
  p = 1,
  kink = c("off", "on"),
  kernel = c("tri", "triangular", "epa", "epanechnikov", "uni", "uniform", "gau",
    "gaussian"),
  bwselect = c("mserd", "imserd", "msetwo", "imsetwo"),
  vce = c("hc1", "hc0", "hc2", "hc3"),
  bwcheck = 20 + p + 1,
  masspoints = c("check", "adjust", "off"),
  C = NULL,
  scaleregul = 1,
  cqt = 0.5
)

Arguments

Y

Dependent variable; a numeric vector of length N, where N is the sample size.

D

Distance-based scores \mathbf{D}_i=(\mathbf{D}_{i}(\mathbf{b}_1),\cdots,\mathbf{D}_{i}(\mathbf{b}_J)); dimension is N \times J where N = sample size and J = number of cutoffs; non-negative values means data point in treatment group and negative values means data point in control group.

b

Optional evaluation points; a matrix or data frame specifying boundary points \mathbf{b}_j = (b_{1j}, b_{2j}), dimension J \times 2.

p

Polynomial order for point estimation. Default is p = 1.

kink

Logical; whether to apply kink adjustment. Options: "on" (default) or "off".

kernel

Kernel function to use. Options are "unif", "uniform" (uniform), "triag", "triangular" (triangular, default), and "epan", "epanechnikov" (Epanechnikov).

bwselect

Bandwidth selection strategy. Options:

  • "mserd". One common MSE-optimal bandwidth selector for the boundary RD treatment effect estimator for each evaluation point (default).

  • "imserd". IMSE-optimal bandwidth selector for the boundary RD treatment effect estimator based on all evaluation points.

  • "msetwo". Two different MSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator for each evaluation point.

  • "imsetwo". Two IMSE-optimal bandwidth selectors (control and treatment) for the boundary RD treatment effect estimator based on all evaluation points.

  • "user provided". User-provided bandwidths. If h is not NULL, then bwselect is overwritten to "user provided".

vce

Variance-covariance estimator for standard errors. Options:

"hc0"

Heteroskedasticity-robust variance estimator without small sample adjustment (White robust).

"hc1"

Heteroskedasticity-robust variance estimator with degrees-of-freedom correction (default).

"hc2"

Heteroskedasticity-robust variance estimator using leverage adjustments.

"hc3"

More conservative heteroskedasticity-robust variance estimator (similar to jackknife correction).

bwcheck

If a positive integer is provided, the preliminary bandwidth used in the calculations is enlarged so that at least bwcheck observations are used. The program stops with “not enough observations” if sample size N < bwcheck. Default is 50 + p + 1.

masspoints

Strategy for handling mass points in the running variable. Options:

"check"

Check for repeated values and adjust inference if needed (default).

"adjust"

Adjust bandwidths to guarantee a sufficient number of unique support points.

"off"

Ignore mass points completely.

C

Cluster ID variable used for cluster-robust variance estimation with degrees-of-freedom weights.Default is C = NULL.

scaleregul

Scaling factor for the regularization term in bandwidth selection. Default is 1.

cqt

Constant controlling subsample fraction for initial bias estimation. Default is 0.5.

Value

An object of class "rdbw2d.dist", containing:

bws

Data frame of optimal bandwidths for each evaluation point:

b1

First coordinate of the evaluation point b1.

b2

Second coordinate of the evaluation point b2.

h0

Bandwidth for observations with distance D_{i}(\mathbf{b}) < 0.

h1

Bandwidth for observations with distance D_{i}(\mathbf{b}) \geq 0.

Nh0

Effective sample size for D_{i}(\mathbf{b}) < 0.

Nh1

Effective sample size for D_{i}(\mathbf{b}) \geq 0.

mseconsts

Data frame of intermediate bias and variance constants used for MSE/IMSE calculations.

opt

List of options used in the function call.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

References

See Also

rd2d.dist, rd2d, summary.rdbw2d.dist, print.rdbw2d.dist

Examples

set.seed(123)
n <- 5000

# Generate running variables x1 and x2
x1 <- rnorm(n)
x2 <- rnorm(n)

# Define treatment assignment: treated if x1 >= 0
d <- as.numeric(x1 >= 0)

# Generate outcome variable y with some treatment effect
y <- 3 + 2 * x1 + 1.5 * x2 + 1.5 * d + rnorm(n, sd = 0.5)

# Define evaluation points (e.g., at the origin and another point)
eval <- data.frame(x.1 = c(0, 0), x.2 = c(0, 1))

# Compute Euclidean distances to evaluation points
dist.a <- sqrt((x1 - eval$x.1[1])^2 + (x2 - eval$x.2[1])^2)
dist.b <- sqrt((x1 - eval$x.1[2])^2 + (x2 - eval$x.2[2])^2)

# Combine distances into a matrix
D <- as.data.frame(cbind(dist.a, dist.b))

# Assign positive distances for treatment group, negative for control
d_expanded <- matrix(rep(2 * d - 1, times = ncol(D)), nrow = nrow(D), ncol = ncol(D))
D <- D * d_expanded

# Run the rd2d.dist function
bws <- rdbw2d.dist(y, D, b = eval)

# View the estimation results
print(bws)
summary(bws)

Summary Method for 2D Local Polynomial RD Estimation

Description

Summarizes estimation and bandwidth results from a 2D local polynomial regression discontinuity (RD) design, as produced by rd2d.

Usage

## S3 method for class 'rd2d'
summary(object, ...)

Arguments

object

An object of class rd2d, typically returned by rd2d.

...

Optional arguments. Supported options include:

  • CBuniform: Logical. If TRUE, displays uniform confidence bands; if FALSE (default), displays pointwise confidence intervals.

  • subset: Integer vector of indices of evaluation points to display. Defaults to all evaluation points.

  • output: Character. Use "main" to display estimation results, or "bw" to display bandwidth information. Default is "main".

  • sep_main: Integer vector of controlling the column widths of the output table when output = "main". Default is c(4, 7, 7, 7, 7, 7, 17).

  • sep_bw: Integer vector of controlling the column widths of the output table when output = "bw". Default is c(4, rep(8,8)).

  • AATE: Integer vector of weights for aggregated average treatment effect (AATE). Should have non-negative entries summing up to one. If provided, an extra row for AATE is added to the output table.

Value

No return value. This function is called for its side effects: it prints a formatted summary of rd2d results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rd2d for estimation using 2D local polynomial RD design.

Supported methods: print.rd2d, summary.rd2d.


Summary Method for 2D Local Polynomial RD Estimation (Distance-Based)

Description

Summarizes estimation and bandwidth results from a 2D local polynomial regression discontinuity (RD) design using distance-based methods, as returned by rd2d.dist.

Usage

## S3 method for class 'rd2d.dist'
summary(object, ...)

Arguments

object

An object of class rd2d.dist, returned by rd2d.dist.

...

Optional arguments. Supported options include:

  • CBuniform: Logical. If TRUE, displays uniform confidence bands; if FALSE (default), displays pointwise confidence intervals.

  • subset: Integer vector of indices of evaluation points to display. Defaults to all evaluation points.

  • output: Character. Use "main" to display estimation results, or "bw" to display bandwidth information. Default is "main".

  • sep_main: Integer vector of length seven controlling the column widths of the output table when output = "main". Default is c(4, 7, 7, 7, 7, 7, 17). When b is not provided, output table has five columns, the second and third entry of sep_main are not used, and can be any place holder.

  • sep_bw: Integer vector of length seven controlling the column widths of the output table when output = "bw". Default is c(4, rep(8,6)). When b is not provided, output table has five columns, the second and third entry of sep_bw are not used, and can be any place holder.

Value

No return value. This function is called for its side effects: it prints a formatted summary of rd2d.dist results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rd2d.dist for estimation using distance-based 2D local polynomial RD design.

Supported methods: print.rd2d.dist, summary.rd2d.dist.


Summary Method for Bandwidth Selection for 2D Local Polynomial RD Design

Description

Summary method for objects of class rdbw2d, displaying bandwidth selection results for 2D local polynomial regression discontinuity designs.

Usage

## S3 method for class 'rdbw2d'
summary(object, ...)

Arguments

object

An object of class rdbw2d, typically returned by rdbw2d.

...

Optional arguments. Supported options include:

  • subset: Integer vector of indices of evaluation points to display. Defaults to all evaluation points.

  • sep: Integer vector of controlling the column widths of the output table. Default is c(4, rep(8, 6)).

Value

No return value. Called for its side effects of printing a formatted summary of rdbw2d results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rdbw2d for bandwidth selection in 2D local polynomial RD design.

Supported methods: print.rdbw2d, summary.rdbw2d.


Summary Method for Bandwidth Selection in 2D Local Polynomial RD Design (Distance-Based)

Description

Summarizes bandwidth selection results from a 2D local polynomial regression discontinuity (RD) design using distance-based methods, as returned by rdbw2d.dist.

Usage

## S3 method for class 'rdbw2d.dist'
summary(object, ...)

Arguments

object

An object of class rdbw2d.dist, returned by rdbw2d.dist.

...

Optional arguments. Supported options include:

  • subset: Integer vector of indices of evaluation points to display. Defaults to all evaluation points.

  • sep: Integer vector of length five controlling the column widths of the output table. Default is c(4, 8, 8, 14, 14). When b is not provided, output table has three columns, the second and third entry of sep are not used, and can be any place holder.

Value

No return value. This function is called for its side effects: it prints a formatted summary of rdbw2d.dist results.

Author(s)

Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu
Rocío Titiunik, Princeton University. titiunik@princeton.edu
Ruiqi Rae Yu, Princeton University. rae.yu@princeton.edu

See Also

rdbw2d.dist for bandwidth selection using 2D local polynomial RD design with distance-based methods.

Supported methods: print.rdbw2d.dist, summary.rdbw2d.dist.