R | 教程 RDD断点有效性和稳健性分析
“社会科学中的机器学习”第466篇推送
rdrobust
进行断点回归并呈现结果。但要利用RD进行研究设计首先需要证明断点的有效性,其次还需要对回归结果进行稳健性检验。本次推送就将结合rdrobust
介绍如何进行断点有效性和结果稳健性检验。RDD中的有效性检验
rdrobust
函数进行检验。预期结果应该为其它变量的系数在统计学上不显著,具体代码如下rddensity
中的对应函数进行McCrary检验,文章数据仍然为上期推送的参议员数据,具体代码如下library(rddensity)
data(rdrobust_RDsenate)
rdplotdensity(rddensity(rdrobust_RDsenate$margin), X = rdrobust_RDsenate$margin)
RDD中的稳健性检验
rdrobust
进行检验,预期结果为系数不再显著。具体代码如下sen_cut_1 <- rdrobust(rdrobust_RDsenate$vote, rdrobust_RDsenate$margin, c = -2, p = 1, kernel = 'triangular', bwselect = 'msetwo')
sen_cut_2 <- rdrobust(rdrobust_RDsenate$vote, rdrobust_RDsenate$margin, c = -1, p = 1, kernel = 'triangular', bwselect = 'msetwo')
sen_cut_3 <- rdrobust(rdrobust_RDsenate$vote, rdrobust_RDsenate$margin, c = 0, p = 1, kernel = 'triangular', bwselect = 'msetwo')
sen_cut_4 <- rdrobust(rdrobust_RDsenate$vote, rdrobust_RDsenate$margin, c = 1, p = 1, kernel = 'triangular', bwselect = 'msetwo')
sen_cut_5 <- rdrobust(rdrobust_RDsenate$vote, rdrobust_RDsenate$margin, c = 2, p = 1, kernel = 'triangular', bwselect = 'msetwo')
## 创建含有coef和se的数据帧
coef <- c(sen_cut_1$coef[1], sen_cut_2$coef[1], sen_cut_3$coef[1], sen_cut_4$coef[1], sen_cut_5$coef[1])
se <- c(sen_cut_1$se[1], sen_cut_2$se[1], sen_cut_3$se[1], sen_cut_4$se[1], sen_cut_5$se[1])
robust_cutpoint <- data.frame(position = c(-2:2), coef, se)
## 利用ggplot2画图
(photo2 <- ggplot(data = robust_cutpoint, aes(x = position)) + geom_point(aes(y = coef), shape = 15)) + geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se), width=.03) + geom_hline(yintercept = 0, colour = 'red')
rdrobust_RD_hole_1 <- subset(rdrobust_RDsenate, abs(margin) > 0.3)
rdrobust_RD_hole_2 <- subset(rdrobust_RDsenate, abs(margin) > 0.4)
rdrobust_RD_hole_3 <- subset(rdrobust_RDsenate, abs(margin) > 0.5)
sen_hole_1 <- rdrobust(rdrobust_RD_hole_1$vote, rdrobust_RD_hole_1$margin, c = 0, p = 1, kernel = 'triangular', bwselect = 'msetwo')
sen_hole_2 <- rdrobust(rdrobust_RD_hole_2$vote, rdrobust_RD_hole_2$margin, c = 0, p = 1, kernel = 'triangular', bwselect = 'msetwo')
sen_hole_3 <- rdrobust(rdrobust_RD_hole_3$vote, rdrobust_RD_hole_3$margin, c = 0, p = 1, kernel = 'triangular', bwselect = 'msetwo')
rdbwselect
计算得出的若干种最优带宽。若回归系数依然显著,则可证明结果稳健性。具体代码如下sen_bandwidth_2 <- rdrobust(rdrobust_RD_hole_2$vote, rdrobust_RD_hole_2$margin, c = 0, p = 1, kernel = 'triangular', bwselect = 'cerrd')
sen_bandwitch_3 <- rdrobust(rdrobust_RD_hole_3$vote, rdrobust_RD_hole_3$margin, c = 0, p = 1, kernel = 'triangular', bwselect = 'cercomb')
注:操作平台为RStudio v1.4 Preview Release
文章来源:https://blog.rstudio.com/2020/09/30/rstudio-v1-4-preview-visual-markdown-editing/,更多请点击“阅读原文”