Skip to content

Commit

Permalink
Merge pull request #363 from grantmcdermott/did_glance_custom
Browse files Browse the repository at this point in the history
did glance custom
  • Loading branch information
vincentarelbundock committed Aug 16, 2021
2 parents f1a8e6f + 9d28af3 commit d00164b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ Suggests:
gamlss,
lme4,
MASS,
nnet
nnet,
did
License: GPL-3
Encoding: UTF-8
LazyData: false
Expand Down
21 changes: 21 additions & 0 deletions R/glance_custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ glance_custom_internal.felm <- function(x, vcov_type = NULL, ...) {
return(out)
}

#' @inherit glance_custom_internal
#' @keywords internal
glance_custom_internal.MP <- function(x, vcov_type = NULL, ...) {
assert_dependency("did")
out <- data.frame(row.names = "firstrow")
if (is.null(vcov_type) || !vcov_type %in% c("vector", "matrix", "function")) {
if (x$DIDparams$bstrap) {
if (!is.null(x$DIDparams$clustervars)) {
cluster_vars = paste(x$DIDparams$clustervars, collapse = " & ")
} else {
cluster_vars = x$DIDparams$idname
}
out[['vcov.type']] <- paste0("Clustered (", cluster_vars, ")")
}
}
row.names(out) <- NULL
return(out)
}
#' @inherit glance_custom_internal
#' @keywords internal
glance_custom_internal.AGGTEobj <- glance_custom_internal.MP

##' @inherit glance_custom
##' @noRd
Expand Down
14 changes: 14 additions & 0 deletions man/glance_custom_internal.AGGTEobj.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/glance_custom_internal.MP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-supported.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,19 @@ test_that("consistent gof std error display fixest/lfe/estimatr", {
expect_equal(tab$felm[nrow(tab)], "Clustered (vs)")
expect_equal(tab$estimatr[nrow(tab)], "Clustered (vs)")
})

test_that("consistent gof std error display did", {
testthat::skip_if_not_installed("did")
library(did)
data(mpdta, package = 'did')
mpdta$newvar <- substr(mpdta$countyreal, 1, 2)
mod1 <- att_gt(yname = "lemp", gname = "first.treat", idname = "countyreal",
tname = "year", xformla = ~1, data = mpdta)
mod2 <- att_gt(yname = "lemp", gname = "first.treat", idname = "countyreal",
tname = "year", xformla = ~1, data = mpdta,
clustervars = c('countyreal', 'newvar'))
mods <- list('mod1' = mod1, 'mod2' = mod2)
tab <- msummary(mods, gof_omit = 'Num|ngroup|ntime|control|method', output = 'data.frame')
expect_equal(tab$mod1[nrow(tab)], "Clustered (countyreal)")
expect_equal(tab$mod2[nrow(tab)], "Clustered (countyreal & newvar)")
})

0 comments on commit d00164b

Please sign in to comment.