iwm94i94.hischshr1520f.df <-
haven::read_dta("../input/meyersson_1994/regdata0.dta")
df <-
df %>%
dplyr::mutate(
y = 100 * hischshr1520f,
x = 100 * iwm94,
t = i94
)
df %>%
dplyr::select(y, x, t) %>%
modelsummary::datasummary_skim()
| Unique (#) | Missing (%) | Mean | SD | Min | Median | Max | ||
|---|---|---|---|---|---|---|---|---|
| y | 2616 | 1 | 15.4 | 9.7 | 0.0 | 14.5 | 68.0 | |
| x | 2659 | 17 | -27.9 | 22.2 | -100.0 | -31.0 | 99.1 | |
| t | 3 | 17 | 0.1 | 0.3 | 0.0 | 0.0 | 1.0 |
df %>% ggplot(aes(x = x, y = t)) + geom_point() + theme_classic()
## Warning: Removed 544 rows containing missing values (geom_point).
df %>% ggplot(aes(x = x, y = y)) + geom_point() + geom_vline(xintercept = 0) + theme_classic()
rdrobust::rdplotbinselect = "es".p <- rdrobust::rdplot(y = df$y, x = df$x, c = 0, nbins = c(20, 20), binselect = "es", y.lim = c(0, 25))
p
## Call: rdplot ## ## Number of Obs. 2630 ## Kernel Uniform ## ## Number of Obs. 2315 315 ## Eff. Number of Obs. 2315 315 ## Order poly. fit (p) 4 4 ## BW poly. fit (h) 100.000 99.051 ## Number of bins scale 1.000 1.000
rdrobust::rdplotbinselect = "qs".p <- rdrobust::rdplot(y = df$y, x = df$x, c = 0, nbins = c(20, 20), binselect = "qs", y.lim = c(0, 25))
p
## Call: rdplot ## ## Number of Obs. 2630 ## Kernel Uniform ## ## Number of Obs. 2315 315 ## Eff. Number of Obs. 2315 315 ## Order poly. fit (p) 4 4 ## BW poly. fit (h) 100.000 99.051 ## Number of bins scale 1.000 1.000
rdrobus:rdplotbinselect = "espr" or binselect = "es" omitting nbins option:rdrobust::rdplot(y = df$y, x = df$x, c = 0, binselect = "espr", y.lim = c(0, 25))
rdrobus:rdplotbinselect = "qspr" or binselect = "qs" omitting nbins option:rdrobust::rdplot(y = df$y, x = df$x, c = 0, binselect = "qspr", y.lim = c(0, 25))
modelsummary for rdrobust resultstidy.rdrobust <- function(object, ...){
ret <- data.frame(term = row.names(object$coef),
estimate = object$coef[, 1],
std.error = object$se[, 1],
statistic = object$z[, 1],
p.value = object$pv[, 1],
conf.low = object$ci[,1],
conf.high = object$ci[, 2])
row.names(ret) <- NULL
ret
}
modelsummary for rdrobust resultsglance.rdrobust <- function(object, ...){
ret <- data.frame(nobs.left = object$N[1],
nobs.right = object$N[2],
nobs.effective.left = object$N_h[1],
nobs.effective.right = object$N_h[2],
cutoff = object$c,
order.regression = object$q,
order.bias = object$q,
kernel = object$kernel,
bwselect = object$bwselect)
ret
}
rdrobust: \(h = 20\), uniform kernelresult <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, kernel = "uniform", p = 1, h = 20) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 2.927 |
| (1.235) | |
| Bias-Corrected | 2.944 |
| (1.235) | |
| Robust | 2.944 |
| (1.799) | |
| bwselect | Manual |
| cutoff | 0.000 |
| kernel | Uniform |
| nobs.effective.left | 608.000 |
| nobs.effective.right | 280.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
rdrobust: \(h = 20\), triangular kernelresult <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, kernel = "triangular", p = 1, h = 20) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 2.937 |
| (1.343) | |
| Bias-Corrected | 2.649 |
| (1.343) | |
| Robust | 2.649 |
| (1.921) | |
| bwselect | Manual |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 608.000 |
| nobs.effective.right | 280.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
rdrobust::rdbwselectbw <- rdrobust::rdbwselect(y = df$y, x = df$x, c = 0, kernel = "triangular", p = 1, bwselect = "mserd") bw$bws
## h (left) h (right) b (left) b (right) ## mserd 17.24268 17.24268 28.57537 28.57537
h (left) and h(right) for the point estimation.bwselect = "msetwo", we get different bandwidth for the left and right.b (left) and b(right) are used later for a robust inference.rdrobust: MSE-optimal bandwidth, triangular kernelresult <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, kernel = "triangular", p = 1, h = bw$bws[1]) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 3.020 |
| (1.427) | |
| Bias-Corrected | 2.106 |
| (1.427) | |
| Robust | 2.106 |
| (2.054) | |
| bwselect | Manual |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 529.000 |
| nobs.effective.right | 266.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
rdrobust: MSE-optimal bandwidth, triangular kernelresult <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, kernel = "triangular", p = 1, bwselect = "mserd") result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 3.020 |
| (1.427) | |
| Bias-Corrected | 2.983 |
| (1.427) | |
| Robust | 2.983 |
| (1.680) | |
| bwselect | mserd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 529.000 |
| nobs.effective.right | 266.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
Conventional row is the standard error for the least squares method.Bias-Corrected row represent this result: the estimated is corrected, but the standard error is same with the conventional standard error.Robust row shows this result: the point estimate is same with bias-corrected, but the standard error is larger than the bias-corrected standard error.rdrobust: MSE-optimal bandwidth, triangular kernelall = TRUE:result <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, kernel = "triangular", p = 1, bwselect = "mserd", all = TRUE) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 3.020 |
| (1.427) | |
| Bias-Corrected | 2.983 |
| (1.427) | |
| Robust | 2.983 |
| (1.680) | |
| bwselect | mserd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 529.000 |
| nobs.effective.right | 266.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
rdrobust: CER-optimal bandwidth, triangular kernelbwselect = "cerrd".result <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, kernel = "triangular", p = 1, bwselect = "cerrd", all = TRUE) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 2.430 |
| (1.682) | |
| Bias-Corrected | 2.411 |
| (1.682) | |
| Robust | 2.411 |
| (1.821) | |
| bwselect | cerrd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 360.000 |
| nobs.effective.right | 216.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
\[ \begin{split} \check{\tau}: \check{Y}_i^{obs} &= \check{\alpha} + T_i \cdot \check{\tau} + X_i \cdot \check{\beta}_- + T_i \cdot X_i \cdot \check{\beta}_+\\ &+ (1 - T_i) \cdot \mathbf{Z}_i^{obs'} \check{\gamma}_- + T_i \cdot \mathbf{Z}_i^{obs'} \check{\gamma}_+. \end{split} \]
vshr_islam1994: Islamic vote percentage in 1994.partycount: the number of parties receiving votes in 1994.lpop1994: the logarithm of the population in 1994.merkezi: district center indicator.merkezp: province center indicator.subbuyuk: sub-metro centor indicator.buyuk: metro centor indicator.rdrobust::rdrobustz <- df %>% dplyr::select(vshr_islam1994, partycount, lpop1994, merkezi, merkezp, subbuyuk, buyuk) result <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, covs = z, kernel = "triangular", p = 1, bwselect = "mserd", all = TRUE) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 3.108 |
| (1.284) | |
| Bias-Corrected | 3.163 |
| (1.284) | |
| Robust | 3.163 |
| (1.515) | |
| bwselect | mserd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 448.000 |
| nobs.effective.right | 241.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
rdrobust::rdrobustprovince_post.result <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, covs = z, kernel = "triangular", p = 1, bwselect = "mserd", all = TRUE, cluster = df$province_post) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 3.146 |
| (1.301) | |
| Bias-Corrected | 3.199 |
| (1.301) | |
| Robust | 3.199 |
| (1.508) | |
| bwselect | mserd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 481.000 |
| nobs.effective.right | 254.000 |
| nobs.left | 2315.000 |
| nobs.right | 315.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
rdrobust::rdplot(y = df$lpop1994, x = df$x, c = 0, binselect = "espr")
result <- rdrobust::rdrobust(y = df$lpop1994, x = df$x, c = 0, kernel = "triangular", p = 1, bwselect = "mserd", all = TRUE) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 0.013 |
| (0.290) | |
| Bias-Corrected | 0.002 |
| (0.290) | |
| Robust | 0.002 |
| (0.346) | |
| bwselect | mserd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 385.000 |
| nobs.effective.right | 232.000 |
| nobs.left | 2332.000 |
| nobs.right | 328.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
df_sub <- df %>% dplyr::filter(!is.na(x), !is.na(lpop1994), !is.na(vshr_islam1994))
result_permtest <- RATest::RDperm(W = c("lpop1994", "vshr_islam1994"), z = "x", data = df_sub)
summary(result_permtest)
## ## ********************************************************** ## ** RD Distribution Test using permutations ** ## ********************************************************** ## Running Variable: x ## Cutoff: 0 ## q: Defined by User ## Test Statistic: CvM ## Number of Permutations: 499 ## Number of Obs: 2660 ## ## ********************************************************** ## H0: 'Continuity of the baseline covariates at the cutoff' ## ********************************************************** ## ## Estimates: ## T(Sn) Pr(>|z|) q ## lpop1994 0.03 0.52 10 ## vshr_islam1994 0.03 0.48 10 ## Joint.Test 0.05 0.6 10 ## --- ## Signif. codes: 0.01 '***' 0.05 '**' 0.1 '*'
df %>% ggplot(aes(x = x)) + geom_histogram(breaks = seq(-100, 100, 5)) + theme_classic() + geom_vline(xintercept = 0)
## Warning: Removed 544 rows containing non-finite values (stat_bin).
n <- df %>% dplyr::filter(abs(x) <= 2) %>% dplyr::group_by((x >= 0)) %>% dplyr::count() n
## # A tibble: 2 x 2 ## # Groups: (x >= 0) [2] ## `(x >= 0)` n ## <lgl> <int> ## 1 FALSE 47 ## 2 TRUE 54
binom.test(n$n[2], sum(n$n), 1/2)
## ## Exact binomial test ## ## data: n$n[2] and sum(n$n) ## number of successes = 54, number of trials = 101, p-value = 0.5507 ## alternative hypothesis: true probability of success is not equal to 0.5 ## 95 percent confidence interval: ## 0.4326763 0.6345451 ## sample estimates: ## probability of success ## 0.5346535
rddensity::rddensityresult <- rddensity::rddensity(df$x, c = 0)
## Warning in rddensity::rddensity(df$x, c = 0): 544 missing observations are ignored.
result$test$p_jk
## [1] 0.3574353
result <- rdrobust::rdrobust(y = df$y, x = df$x, c = 1, kernel = "triangular", p = 1, bwselect = "mserd", all = TRUE) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 1.749 |
| (1.511) | |
| Bias-Corrected | 1.422 |
| (1.511) | |
| Robust | 1.422 |
| (1.758) | |
| bwselect | mserd |
| cutoff | 1.000 |
| kernel | Triangular |
| nobs.effective.left | 504.000 |
| nobs.effective.right | 237.000 |
| nobs.left | 2345.000 |
| nobs.right | 285.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |
df_sub <- df %>% dplyr::filter(abs(x) >= 0.3) result <- rdrobust::rdrobust(y = df_sub$y, x = df_sub$x, c = 0, kernel = "triangular", p = 1, bwselect = "mserd", all = TRUE) result %>% modelsummary::modelsummary()
| Model 1 | |
|---|---|
| Conventional | 3.414 |
| (1.517) | |
| Bias-Corrected | 3.450 |
| (1.517) | |
| Robust | 3.450 |
| (1.794) | |
| bwselect | mserd |
| cutoff | 0.000 |
| kernel | Triangular |
| nobs.effective.left | 482.000 |
| nobs.effective.right | 248.000 |
| nobs.left | 2308.000 |
| nobs.right | 309.000 |
| order.bias | 2.000 |
| order.regression | 2.000 |