Skip to content

Commit 02770c7

Browse files
authored
fixest: Incorrect standard errors and error (#1040)
* `fixest`: Incorrect standard errors and error Fixes #1039 * fix * fix * fix * minor * fix
1 parent c91e4a8 commit 02770c7

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: parameters
33
Title: Processing of Model Parameters
4-
Version: 0.23.0.6
4+
Version: 0.23.0.7
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",
@@ -113,6 +113,7 @@ Suggests:
113113
coxme,
114114
cplm,
115115
dbscan,
116+
did,
116117
distributional,
117118
domir (>= 0.2.0),
118119
drc,

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Fixed bug when extracting 'pretty labels' for model parameters, which could
1111
fail when predictors were character vectors.
1212

13+
* Fixed bug with inaccurate standard errors for models from package *fixest*
14+
that used the `sunab()` function in the formula.
15+
1316
# parameters 0.23.0
1417

1518
## Breaking Changes

R/methods_fixest.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ standard_error.fixest <- function(model, vcov = NULL, vcov_args = NULL, ...) {
7373
params <- insight::get_parameters(model)
7474

7575
if (is.null(vcov)) {
76+
# get standard errors from summary
77+
# see https://github.com/easystats/parameters/issues/1039
7678
stats <- summary(model)
77-
SE <- as.vector(stats$se)
79+
SE <- as.vector(stats$coeftable[, "Std. Error"])
7880
} else {
7981
# we don't want to wrap this in a tryCatch because the `fixest` error is
8082
# informative when `vcov` is wrong.

tests/testthat/test-model_parameters.fixest.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,21 @@ test_that("robust standard errors", {
115115
expect_error(parameters(mod, vcov = "hetero"), NA)
116116
expect_error(parameters(mod, vcov = "iid"), NA)
117117
})
118+
119+
120+
test_that("standard errors, Sun and Abraham", {
121+
skip_if_not_installed("did")
122+
data(mpdta, package = "did")
123+
m <- fixest::feols(
124+
lemp ~ sunab(first.treat, year, ref.p = -1:-4, att = TRUE) | countyreal + year,
125+
data = mpdta,
126+
cluster = ~countyreal
127+
)
128+
out <- model_parameters(m)
129+
expect_equal(out$SE, m$coeftable[, "Std. Error"], tolerance = 1e-4, ignore_attr = TRUE)
130+
131+
data(base_stagg, package = "fixest")
132+
m <- fixest::feols(y ~ x1 + sunab(year_treated, year) | id + year, base_stagg)
133+
out <- model_parameters(m)
134+
expect_equal(out$SE, m$coeftable[, "Std. Error"], tolerance = 1e-4, ignore_attr = TRUE)
135+
})

0 commit comments

Comments
 (0)