library(tidyverse)
library(rdrobust)
library(rdlocrand)
hansen <- haven::read_dta(
"https://github.com/kylebutts/UARK_5783/raw/refs/heads/main/Slides/04_RDD/data/hansen_dwi.dta"
)
est_rdlocrand <- rdlocrand::rdrandinf(
Y = hansen$recidivism,
R = hansen$bac1,
cutoff = 0.08,
p = 1,
wl = 0.00,
wr = 0.16,
)
#>
#> Selected window = [0;0.16]
#>
#> Running randomization-based test...
#> Randomization-based test complete.
#>
#>
#> Number of obs = 214558
#> Order of poly = 1
#> Kernel type = uniform
#> Reps = 1000
#> Window = set by user
#> H0: tau = 0.000
#> Randomization = fixed margins
#>
#> Cutoff c = 0.080 Left of c Right of c
#> Number of obs 23010 191548
#> Eff. number of obs 23010 118121
#> Mean of outcome 0.117 0.108
#> S.d. of outcome 0.321 0.311
#> Window 0.000 0.160
#>
#> ================================================================================
#> Finite sample Large sample
#> ------------------ -----------------------------
#> Statistic T P>|T| P>|T| Power vs d = 0.161
#> ================================================================================
#> Diff. in means -0.021 0.000 0.000 1.000
#> ================================================================================
est_rdrobust <- rdrobust::rdrobust(
y = hansen$recidivism,
x = hansen$bac1,
c = 0.08,
p = 1,
h = 0.08,
kernel = "uniform"
)
est_rdlocrand$obs.stat
#> [1] -0.02147108
est_rdrobust$Estimate[1, "tau.us"]
#> tau.us
#> -0.02147108Created on 2025-10-22 with reprex v2.1.1