df_raw <- haven::read_dta("../input/amarante_2016/anonymized_data/peso4_anonymized.dta") df_raw %>% dplyr::select(bajo2500, newind, ing_ciud_txu_hh9) %>% modelsummary::datasummary_skim(histogram = FALSE, fmt = 3)
Unique (#) | Missing (%) | Mean | SD | Min | Median | Max | |
---|---|---|---|---|---|---|---|
bajo2500 | 3 | 0 | 0.087 | 0.282 | 0.000 | 0.000 | 1.000 |
newind | 38321 | 69 | -0.161 | 0.249 | -0.946 | -0.096 | 0.190 |
ing_ciud_txu_hh9 | 1097 | 4 | 0.069 | 0.281 | 0.000 | 0.000 | 2.254 |
df <- df_raw %>% dplyr::mutate(y = bajo2500, x = newind, d = (ing_ciud_txu_hh9 > 0)) %>% dplyr::select(y, x, d) %>% tidyr::drop_na()
rdrobust::rdplot(y = df$d, x = df$x, c = 0, binselect = "qspr", x.label = "Normalized income", y.label = "Receipt of the income transfer")
## [1] "Mass points detected in the running variable."
rdrobust::rdplot(y = df$y, x = df$x, c = 0, binselect = "qspr", x.label = "Normalized income", y.label = "Low birth weight")
## [1] "Mass points detected in the running variable."
result <- rdrobust::rdrobust(y = df$y, x = df$x, c = 0, fuzzy = df$d, bwselect = "mserd", kernel = "triangular", all = TRUE, masspoints = "off") cbind(result$coef, result$se) %>% kbl() %>% kable_styling()
Coeff | Std. Err. | |
---|---|---|
Conventional | -0.0737664 | 0.0464639 |
Bias-Corrected | -0.0839237 | 0.0464639 |
Robust | -0.0839237 | 0.0517589 |
\[ \begin{split} &\lim_{v \downarrow 0} \frac{d \mathbb{E}[Y|V = v]}{\partial v}\\ &= \lim_{v \downarrow 0} \frac{d}{dv} \int y[b(v), v, u] \frac{f_{V|U = u}(v)}{f_V(v)} d F_U(u)\\ &= \lim_{v \downarrow 0} \int \frac{d}{dv} y[b(v), v, u] \frac{f_{V|U = u}(v)}{f_V(v)} d F_U(u)\\ &= \lim_{v \downarrow 0} b'(v) \int \frac{\partial}{\partial b} y[b(v), v, u] \frac{f_{V|U = u}(v)}{f_V(v)} d F_U(u)\\ &+ \int \Bigg[ \frac{\partial }{\partial v} y[b(v), v, u] \frac{f_{V|U = u}(v)}{f_V(v)} + y[b(v), v, u] \frac{\partial}{\partial v} \frac{f_{V|U = u}(v)}{f_V(v)} \Bigg] d F_U(u). \end{split} \]
\[ \begin{split} & \lim_{v \downarrow 0} \frac{d \mathbb{E}[Y|V = v]}{\partial v} - \lim_{v \uparrow 0} \frac{d \mathbb{E}[Y|V = v]}{\partial v}\\ &= \lim_{v \downarrow 0} b'(v) \int \frac{\partial}{\partial b} y[b(v), v, u] \frac{f_{V|U = u}(v)}{f_V(v)} d F_U(u) \\ &- \lim_{v \uparrow 0} b'(v) \int \frac{\partial}{\partial b} y[b(v), v, u] \frac{f_{V|U = u}(v)}{f_V(v)} d F_U(u)\\ &= \Bigg[\lim_{v \downarrow 0} b'(v) - \lim_{v \uparrow 0} b'(v)\Bigg]\cdot \int \frac{\partial}{\partial b} y[b(0), 0, u] \frac{f_{V|U = u}(0)}{f_V(0)} d F_U(u)\\ &= \Bigg[\lim_{v \downarrow 0} b'(v) - \lim_{v \uparrow 0} b'(v)\Bigg] \cdot TT[b(0), 0]. \end{split} \]
set.seed(1) N <- 1000 compute_y <- function(b, v, u) { y <- 2 * b + 1 * v + u return(y) } compute_b <- function(v) { b <- 2 * v - 1 * v * (v > 0) return(b) }
df <- tibble::tibble( u = rnorm(N), v = rnorm(N) + 0.1 * u ) %>% dplyr::mutate( b = compute_b(v), y = compute_y(b, v, u) )
df %>% ggplot(aes(x = v, y = b)) + geom_point() + theme_classic()
df %>% ggplot(aes(x = v, y = y)) + geom_point() + theme_classic()
rdrobust::rdplot(y = df$y, x = df$v, c = 0, binselect = "espr", x.label = "v", y.label = "y")
rdrobust::rdrobust
does not accept a sharp RKD with a continuous treatmentresult <- rdrobust::rdrobust(y = df$y, x = df$v, c = 0, deriv = 1, kernel = "triangular", bwselect = "mserd", all = "true") cbind(result$coef, result$se) %>% kbl() %>% kable_styling()
Coeff | Std. Err. | |
---|---|---|
Conventional | -2.450270 | 0.4783327 |
Bias-Corrected | -2.618864 | 0.4783327 |
Robust | -2.618864 | 0.7786943 |
set.seed(1) N <- 10000 cutoff <- c(0, 0) beta <- 50 df <- tibble::tibble( longitude = rnorm(N, 0, 10), latitude = rnorm(N, 0, 10) ) %>% dplyr::mutate( outcome_0 = longitude + latitude + rnorm(length(longitude)), outcome_1 = outcome_0 + beta + rnorm(length(outcome_0)), treatment = (longitude < cutoff[1]) & (latitude < cutoff[2]), outcome = outcome_0 * (1 - treatment) + outcome_1 * treatment )
df %>% ggplot( aes( x = longitude, y = latitude, color = treatment ) ) + geom_point() + scale_colour_viridis_d() + theme_classic()
df %>% ggplot( aes( x = longitude, y = latitude, colour = outcome ) ) + geom_point() + scale_colour_viridis_c() + theme_classic()
result <- rdmulti::rdms( Y = df$outcome, X = df$longitude, X2 = df$latitude, zvar = df$treatment, C = 0, C2 = 0, bwselectvec = c("mserd", "mserd"), kernelvec = c("triangular", "triangular") )
## ## ================================================================================ ## Cutoff Coef. P-value 95% CI hl hr Nh ## ================================================================================ ## (0.00,0.00) 50.239 0.000 49.618 51.059 4.970 4.970 1192 ## ================================================================================
result <- rdmulti::rdms( Y = df$outcome, X = df$longitude, X2 = df$latitude, zvar = df$treatment, C = 0, C2 = -20, bwselectvec = c("mserd", "mserd"), kernelvec = c("triangular", "triangular") )
## ## ================================================================================ ## Cutoff Coef. P-value 95% CI hl hr Nh ## ================================================================================ ## (0.00,-20.00) 50.101 0.000 47.364 53.389 4.155 4.155 121 ## ================================================================================