Skip to content

boottest fails with fixest model if FE is a character instead of factor #161

@dwinkler1

Description

@dwinkler1

Here is a reproducible example

set.seed(1234)
N <- 1000
x <- rnorm(N, 0, 10)
fe <- sample(letters, 100, replace = TRUE)
femu <- rnorm(N, seq_along(fe))
fesd <- rexp(N, seq_along(fe))
y <- 5 * x + femu + rnorm(N, fesd)
df <- data.frame(y, x, fe)
feols(y ~ x | fe, df, vcov = ~fe)
# 1. Fails
boottest(feols(y ~ x | fe, df), clustid = "fe", B = 9999, param = "x", fe = "fe")
# 2. Fails
boottest(feols(y ~ x | factor(fe), df), clustid = "fe", B = 9999, param = "x", fe = "fe")
# 3. Works
df$fe <- factor(df$fe)
boottest(feols(y ~ x | fe, df), clustid = "fe", B = 9999, param = "x", fe = "fe")

Debugging 1. has lead me to this function as the culprit:

debug: suppressWarnings(expand.model.frame(model = manipulate_object(object), 
    extras = clustid_fml, na.expand = FALSE, envir = call_env))

For 2. the error is here:

debug: if (!(fe %in% object$fixef_vars)) {
    rlang::abort(paste("The fixed effect to be projected out in the bootstrap,", 
        fe, "is not included as a dedicated fixed effect\n                   in the estimated model."))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions