rdplotdensity
constructs density plot near the cutoff. It is based on the
local polynomial density estimator proposed in Cattaneo, Jansson and Ma (2019).
Companion command: rddensity
for manipulation testing.
A companion Stata
package is described in Cattaneo, Jansson and Ma (2018).
Related Stata and R packages useful for inference in regression discontinuity (RD) designs are described at https://sites.google.com/site/rdpackages.
rdplotdensity(rdd, X, plotRange = NULL, plotN = 10,
plotGrid = c("es", "qs"), alpha = 0.05, type = NULL,
CItype = NULL, title = "", xlabel = "", ylabel = "",
lty = NULL, lwd = NULL, lcol = NULL, pty = NULL, pwd = NULL,
pcol = NULL, CIshade = NULL, CIcol = NULL, legendTitle = NULL,
legendGroups = NULL)
Object returned by rddensity
Numeric vector or one dimensional matrix / data frame, the running variable.
Numeric, specifies the lower and upper bound for density plot. By default it is three bandwidths around the cutoff.
Numeric, specifies the number of grid points used for density plot on each side. If more than one is provided, they will be applied to the two sides accordingly. By default 10 points are used on each side.
String, specifies the position of grid points. Can be either evenly spaced (default, "es"
),
or quantile spaced ("qs"
).
Numeric scalar between 0 and 1, the significance level for plotting confidence regions. If more than one is provided, they will be applied to the two sides accordingly.
String, one of "line"
(default), "points"
or "both"
, how
the point estimates are plotted. If more than one is provided, they will be applied to the two sides
accordingly.
String, one of "region"
(shaded region, default), "line"
(dashed lines),
"ebar"
(error bars), "all"
(all of the previous) or "none"
(no confidence region),
how the confidence region should be plotted. If more than one is provided, they will be applied to the two sides
accordingly.
Strings, title of the plot and labels for x- and y-axis.
Scatter plot size for point estimates, only effective if type
is "points"
or
"both"
. Should be strictly positive. If more than one is provided, they will be applied to the two sides
accordingly.
Numeric, opaqueness of the confidence region, should be between 0 (transparent) and 1. Default is 0.2. If more than one is provided, they will be applied to the two sides accordingly.
String, title of legend.
String Vector, group names used in legend.
Matrices containing estimation results on the two side, with (1) grid
(grid points), (2) bw
(bandwidths), (3) nh
(effective/local sample sizes), (4) f_p
(point estimates with p-th order local polynomial),
(5) f_q
(point estimates with q-th order local polynomial, only if option q
is nonzero),
(6) se_p
(standard error corresponding to f_p
), and (7) se_q
(standard error
corresponding to f_q
).
A stadnard ggplot
object is returned, hence can be used for further customization.
M.D. Cattaneo, M. Jansson and X. Ma. (2018). Manipulation Testing based on Density Discontinuity. Stata Journal 18(1): 234-261.
M.D. Cattaneo, M. Jansson and X. Ma. (2019). Simple Local Polynomial Density Estimators. Journal of the American Statistical Association, forthcoming.
# NOT RUN {
# Generate a random sample with a discontinuous density
set.seed(42)
x <- rnorm(2000, mean = -0.5); x[x>0] <- x[x>0] * 2
# Estimation
rdd <- rddensity(X = x)
# Plot
plot <- rdplotdensity(rdd, x, plotRange = c(-2, 2), plotN = 25)
# }
Run the code above in your browser using DataLab