0

I am trying to include four rdrobust models in a table using modelsummary, but also need to include: N (number of observations), bws (chosen bandwidth) and p (order of the polynomial). The answer to this question was very helpful but I need to add the extra statistics. I tried to include these in the glance and the tidy formula, but keep getting an error. I'm not sure where I'm going wrong.

I tried:

tidy.rdrobust <- function(x, ...) {
   ret <- data.frame(
   term = row.names(x$coef),
   estimate = x$coef[, 1],
   std.error = x$se[, 1],
   p.value = x$pv[, 1]
   N = x$N[,1],
   BW = x$bws[,1]
   )
row.names(ret) <- NULL
  ret
 }

glance.rdrobust <- function(x, ...) {
   ret <- data.frame(
   Kernel = x$kernel,
   Bandwidth = x$bwselect
   )
  ret
 }

And also:

tidy.rdrobust <- function(x, ...) {
  ret <- data.frame(
    term = row.names(x$coef),
    estimate = x$coef[, 1],
    std.error = x$se[, 1],
    p.value = x$pv[, 1]
   )
   row.names(ret) <- NULL
  ret
 }

 glance.rdrobust <- function(x, ...) {
  ret <- data.frame(
    Kernel = x$kernel,
    Bandwidth = x$bwselect,
    BW = x$bws,
    N = x$N
   )
  ret
 }
  • The output of `glance.rdrobust()` must be a data.frame one only ONE ROW. In your code, you sadd `x$N`, which has two elements, so your `ret` data frame will have more than one row. I believe there is a similar problem with `x$bws`. Finally, I strongly recommend you read this post to learn how to write good questions with *minimal reproducible examples* and complete error messages in R: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/16532098 – Vincent Mar 10 '22 at 01:58

0 Answers0