Skip to content

Commit

Permalink
fixest: Incorrect standard errors and error
Browse files Browse the repository at this point in the history
Fixes #1039
  • Loading branch information
strengejacke committed Nov 7, 2024
1 parent c91e4a8 commit 78760be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.23.0.6
Version: 0.23.0.7
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -113,6 +113,7 @@ Suggests:
coxme,
cplm,
dbscan,
did,
distributional,
domir (>= 0.2.0),
drc,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* Fixed bug when extracting 'pretty labels' for model parameters, which could
fail when predictors were character vectors.

* Fixed bug with inaccurate standard errors for models from package *fixest*
that used the `sunab()` function in the formula.

# parameters 0.23.0

## Breaking Changes
Expand Down
10 changes: 8 additions & 2 deletions R/methods_fixest.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ standard_error.fixest <- function(model, vcov = NULL, vcov_args = NULL, ...) {
params <- insight::get_parameters(model)

if (is.null(vcov)) {
stats <- summary(model)
SE <- as.vector(stats$se)
# most reliable is from "coeftable" element
stats <- model$coeftable
SE <- .safe(as.vector(stats[, "Std. Error"]))
# if this fails extract from summary
if (is.null(SE)) {
stats <- summary(model)
SE <- as.vector(stats$se)
}
} else {
# we don't want to wrap this in a tryCatch because the `fixest` error is
# informative when `vcov` is wrong.
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-model_parameters.fixest.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,20 @@ test_that("robust standard errors", {
expect_error(parameters(mod, vcov = "hetero"), NA)
expect_error(parameters(mod, vcov = "iid"), NA)
})


test_that("standard errors, Sun and Abraham", {
data(mpdta, package = "did")
m <- fixest::feols(
lemp ~ sunab(first.treat, year, ref.p = -1:-4, att = TRUE) | countyreal + year,
data = mpdta,
cluster = ~countyreal
)
out <- model_parameters(m)
expect_equal(out$SE, m$coeftable[, "Std. Error"], tolerance = 1e-4, ignore_attr = TRUE)

data(base_stagg, package = "fixest")
m <- fixest::feols(y ~ x1 + sunab(year_treated, year) | id + year, base_stagg)
out <- model_parameters(m)
expect_equal(out$SE, m$coeftable[, "Std. Error"], tolerance = 1e-4, ignore_attr = TRUE)
})

0 comments on commit 78760be

Please sign in to comment.