*! version 1.0 30Aug2016

*! version 2.0 17Apr2020 (complete overhaul from Version 1.0)

Title

next -- Regression discontinuity design (RDD) estimator

Syntax

next
varlist(min=2
max=2)
[if]
[in]
[fw]
[,
options]

where varlist is

Y X

Main
threshold(#) Default value is 0.

minorder(#) Default value is 1.

maxorder(#) Default value is 3.

bins(#) Number of bins used for learning the optimal specification. Default is no binning.

bins_graph(#) Number of bins used for graphing the results. Default is no binning.

alpha_spe(#) Smoothing parameter for squared prediction errors. Default is 0.02.

regtype(string) Regression type (regress (default), logit, or probit).

kernel(string) Kernel type (all (default), uniform, triangular, or epanechnikov).

Reporting
details Print details of the bandwidth learning for each candidate specification.

Description

next simultaneously selects the polynomial specification and bandwidth
that minimizes the prediction error of Y from both sides of a discontinuity threshold.
It achieves this selection by evaluating the combinations of polynomial order, kernel, and bandwidth
that perform best in estimating the next point in the observed sequence on each side of the
discontinuity. For more information on the algorithm, see Next: Machine Learning for Regression Discontinuity.

Using the best order, kernel, and bandwidth for each side, the next command then generates a regression using this specification,
generates an estimate of the local average treatment effect, and generates a spiffy graph.

User Notes:

(1) The first variable in the varlist is the outcome of interest (Y). The second variable in the varlist is the running variable (X).
No other variables should be included.

(2) The graph that is produced plots the raw data (in bins if bins_graph(#) is selected) with circles proportional to the number of observations
that are included at that value of X. The graph also plots the estimated regression specification, with the red line showing the extent of the
left-hand-side bandwidth and blue line showing the extent of the right-hand-side bandwidth. For a nicely generated graph,
please label your Y and X variables prior to running the next command.
The graph uses as a font "LM Roman 12" if this font is installed on your computer. This font can be changed by the user using Stata's Graph Editor.
The graph is not saved by the program, so the user may want to include code after the next command to save the graph, if desired.

(3) Frequency weights can be used. If you have already collapsed your data into bins, then the frequency weight should be the count of the number
of observations that are included in the bin.

(4) Threshold is the threshold for receiving treatment. It is assumed that an observation with X=Threshold is on the right side of the discontinuity.
If an observation that is exactly at the threshold should be considered to be with the group on the left side of the discontinuity,
set the Threshold to be Threshold+Epsilon, where Epsilon is a very small number that will successfully cleave the treatment and control groups
into two approriate parts. (Alternatively, generate a new variable that is -X (i.e., reverse the order of X) and apply the next command using this
tranformed variable).

(5) minorder (maxorder) defines the minimum (maximum) order of the polynomial that you wish to be considered as a candidate specification.
The minimum number of observations on each side must equal 5+maxorder.
This algorithm's usefulness is limited if there are a small number of distinct values of X as there is little scope for learning.

(6) This program is slow, particularly if you have a lot of distinct values of X or if using a logit/probit specification.
It does a lot of learning! To get a quick feel for the data and the program, you might want to set the maxorder and the number of bins to low numbers
(e.g., "maxorder(1) bins(20)"). The program runs a bit faster without the "details" option.

(7) Note that the program automatically bins the data when multiple observations share the same value of X. These observations are then weighted in
the graph. However, the raw, unbinned data are used in the final regression.

(8) The smoothing parameter, "alpha_spe", can be set to any value >0 and <=1. A larger value will mean more smoothing, while a smaller value will put
more emphasis on accurate predictions of the observations that are nearest to the threshold.

(9) If the user chooses "regtype(logit)" or "regtype(probit)", the dependent variable should lie in the range 0 to 1, inclusive.

(10) The default kernel setting is "all", which means that it will evaluate each of the following kernels: uniform, triangular, or epanechnikov.
If you with to force one particular kernel to be used on both sides of the discontinuity, then use the option "kernel(uniform)", "kernel(triangular)", or
"kernel(epanechnikov)".

(11) In the unusual case where Y is constant across a consecutive series of X values near the threshold, the algorithm with "learn" that the best
specification is uniform with a narrow bandwidth as this produces a perfect prediction at this Y-bar. To avoid this result, you might want to bin the data.

(12) This program produces an RD estimate assuming a strict cutoff. For those seeking to produce an estimate in the context of a Fuzzy RD design, this
program can be used to generate the appropriate specification as the first stage in an instrumental variable estimation approach.

Example

Setup (data from Jacob et al., 2012, with simulated treatment effect of -10 at threshold=215)

import excel using https://www.mdrc.org/sites/default/files/img/RDD_Guide_Dataset_0.xls, firstrow sheet("Data")
`"label var posttest "7th Grade Math Posttest Score"' : label var posttest "7th Grade Math Posttest Score"
`"label var pretest "7th Grade Math Pretest Score"' : label var pretest "7th Grade Math Pretest Score"

Run regression discontinuity analysis with default settings, except threshold set at 215 (as in Jacob et al., 2012, data grouped into 30 roughly equal bins and restricting the analysis to a quadratic or lower order polynomial.)

next posttest pretest, threshold(215)

Stored results

Scalars

e(LATE)

e(LATE_t)

e(LATE_se)

e(LATE_p)

Logit/Probit only:
e(LtoR_DISCONTINUITY)

e(LtoR__Chi2)

e(LtoR__DISC_p)

Author

Mark C. Long, University of Washington (corresponding author)

Email marklong@uw.edu

Jordan Rooklyn, Portland Water Bureau

References

Long, M., and J. Rooklyn. 2020.
Next: Machine Learning for Regression Discontinuity.
Working paper.

Jacob, R.T., P. Zhu, M.A. Somers, and H. Bloom. 2012.
A Practical Guide to Regression Discontinuity.
New York: MDRC.

Imbens, G., and K. Kalyanaraman. 2012.
Optimal Bandwidth Choice for the Regression Discontinuity Estimator. Review of Economic Studies, 79(3), 933-959.

Calonico, S., M. D. Cattaneo, and R. Titiunik. 2014.
Robust Nonparametric Confidence Intervals for Regression-Discontinuity Designs. Econometrica 82(6): 2295-2326.

Calonico, S., M. D. Cattaneo, M. H. Farrell, and R. Titiunik. 2017.
drobust: Software for regression-discontinuity designs. The Stata Journal, 17(2), 372–404.

See Also

rd (if installed) ssc install rd (to install this command)
rdrobust (if installed) ssc install rdrobust (to install this command)