Skip to content

Instantly share code, notes, and snippets.

@vincentarelbundock
Created September 21, 2020 16:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincentarelbundock/5ee12d715d59266beb81ff654d2227d5 to your computer and use it in GitHub Desktop.
Save vincentarelbundock/5ee12d715d59266beb81ff654d2227d5 to your computer and use it in GitHub Desktop.
rdrobust & modelsummary
library(rdrobust)
library(modelsummary)
tidy.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
}
glance.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
}
x <- runif(1000, -1, 1)
y <- 5 + 3 * x + 2 * (x >= 0) + rnorm(1000)
fit <- rdrobust(y, x)
modelsummary(fit)
@resulumit
Copy link

resulumit commented Feb 11, 2024

Thank you very much for sharing this script. I think we need to replace q with p on line 22 as:

order.regression = object$p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment