Illustration of continuity argument
rdlocrand
implements Fisher-style testsrdrobust
R/Stata libraries and extensive documentation and extensions, may be most popular and widely applicable default implementationRDHonest
House Election Wins lead to more wins for party
#Load RD package containing Lee (2008) incumbency data
suppressWarnings(suppressMessages(library(rddtools)))
data(house) #Lee data
#Load another package for RD estimation
suppressWarnings(suppressMessages(library(rdrobust))) #Calonic0 2014 robust CIs
suppressWarnings(suppressMessages(library(RDHonest))) #Arstrong Kolesar robust CIs
# Specify x, y, and cutpoint = 0 Dem-Rep vote share
house_rdd<-rdd_data(y=house$y,x=house$x,cutpoint=0)
# Specify same for format of RDHonest package
LEEframe<-data.frame(y=house$y,x=house$x)
# OLS estimate in rddtools library, linear with different slope on each side
(reg_para <- rdd_reg_lm(rdd_object=house_rdd))
## ### RDD regression: parametric ###
## Polynomial order: 1
## Slopes: separate
## Number of obs: 6558 (left: 2740, right: 3818)
##
## Coefficient:
## Estimate Std. Error t value Pr(>|t|)
## D 0.1182314 0.0056799 20.816 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Estimate MSE- optimal bandwidth on Lee data by Imbens-Kalyanaraman procedure
LEEbw<-rdd_bw_ik(house_rdd)
# Local linear RD estimate, different slope on each side
(LEEnp<-rdd_reg_np(rdd_object=house_rdd,bw=LEEbw))
## ### RDD regression: nonparametric local linear###
## Bandwidth: 0.2938561
## Number of obs: 3200 (left: 1594, right: 1606)
##
## Coefficient:
## Estimate Std. Error z value Pr(>|z|)
## D 0.079924 0.009465 8.4443 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Calonico Cattaneo Titiunik bias corrected estimates and CIs
summary(rdrobust(y=house$y,x=house$x,c=0,all = TRUE))
## [1] "Mass points detected in the running variable."
## Call: rdrobust
##
## Number of Obs. 6558
## BW type mserd
## Kernel Triangular
## VCE method NN
##
## Number of Obs. 2740 3818
## Eff. Number of Obs. 789 817
## Order est. (p) 1 1
## Order bias (q) 2 2
## BW est. (h) 0.136 0.136
## BW bias (b) 0.240 0.240
## rho (h/b) 0.565 0.565
## Unique Obs. 2108 2581
##
## =============================================================================
## Method Coef. Std. Err. z P>|z| [ 95% C.I. ]
## =============================================================================
## Conventional 0.064 0.011 5.815 0.000 [0.042 , 0.085]
## Bias-Corrected 0.059 0.011 5.418 0.000 [0.038 , 0.081]
## Robust 0.059 0.013 4.738 0.000 [0.035 , 0.084]
## =============================================================================
## RD plot with bin-scatter and global quartic polynomial estimates
rdplot(y=house$y,x=house$x,c=0,masspoints="off")
# Armstrong-Kolesar CI with bound M of 0.4 on second derivative (sclass T),
# bandwidth optimized for smallest "Fixed Length Confidence Interval"
RDHonest(y~x,data=LEEframe,kern="triangular",M=0.4,opt.criterion = "FLCI",sclass="T")
## Call:
## RDHonest(formula = y ~ x, data = LEEframe, M = 0.4, kern = "triangular",
## opt.criterion = "FLCI", sclass = "T")
##
##
## Inference by se.method:
## Estimate Maximum Bias Std. Error
## nn 0.07810269 0.005018494 0.008338368
##
## Confidence intervals:
## nn (0.05919947, 0.09700591), (0.0593688, Inf), (-Inf, 0.09683658)
##
## Bandwidth: 0.2638011
## Number of effective observations: 645.7353
Balance test
#Run McCrary test
# Estimates density left and right of cutoff
# null is no difference in density
LEEtest<-dens_test(LEEnp,plot=FALSE)
pvalue<-LEEtest[2] #get p value
#Run McCrary test
# Estimates density left and right of cutoff
# null is no difference in density
dens_test(LEEnp)
##
## McCrary Test for no discontinuity of density around cutpoint
##
## data: LEEnp
## z-val = 1.2952, p-value = 0.1952
## alternative hypothesis: Density is discontinuous around cutpoint
## sample estimates:
## Discontinuity
## 0.1035008
Estimates
Bandwidths