rd2d {rd2d}R Documentation

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)

[Package rd2d version 0.0.2 Index]