Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/didFF.R
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,14 @@ didFF <-function(
att = att
)
} else {
# Sigmahat only covers the bins kept above; a dropped bin has no
# standard error to report.
test_se <- base::rep(NA_real_, base::length(point_estimates))
test_se[keep_IF] <- base::sqrt(base::diag(Sigmahat))
implied_dist_table <- base::data.frame(
level = bin2,
test.estimates = point_estimates,
test.se = base::sqrt(base::diag(Sigmahat))
test.se = test_se
)

didFF_out <- base::list(
Expand Down
38 changes: 38 additions & 0 deletions tests/test_distDD.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
library(testthat)
library(didFF)

#-----------------------------------------------------------------------------
# distDD keeps every bin in its table when one of them is dropped from the
# covariance for having a degenerate influence function.
data(mpdta, package = "did")

run_distDD <- function(...) {
suppressWarnings(
distDD(
data = mpdta,
yname = "lemp",
tname = "year",
idname = "countyreal",
gname = "first.treat",
control_group = "nevertreated",
nbins = 6,
seed = 0,
aggte_type = "dynamic",
...
)
)
}

test_that("distDD returns one row per bin when a bin is dropped", {
full <- run_distDD()
dropped <- run_distDD(balance_e = 1)

expect_equal(NROW(full$table), 6)
expect_false(anyNA(full$table$test.se))

expect_equal(NROW(dropped$table), 6)
expect_equal(as.character(dropped$table$level), as.character(full$table$level))
expect_equal(sum(is.na(dropped$table$test.se)), 1)
expect_true(all(dropped$table$test.se[!is.na(dropped$table$test.se)] > 0))
expect_false(anyNA(dropped$table$test.estimates))
})