Skip to content

Number of parameters depends on multiple estimation syntax #631

@leostimpfle

Description

@leostimpfle

Hi @lrberge ! Thanks for all your work on fixest.

I noticed that nparams can differ by one for the same model specification depending on whether multiple estimation syntax is used or not (see example below). Is this intentional?

library(fixest)
set.seed(42)
d <- data.frame(
  Y = rnorm(100),
  X1 = rnorm(100),
  f1 = sample(1:5, 100, replace = TRUE),
  f2 = sample(1:4, 100, replace = TRUE)
)

# Two models Y ~ X1 | f1 and Y ~ X1 | f1 + f2
# estimated via three different formulas

# 1) Single estimation
single_f1 <- feols(Y ~ X1 | f1, data = d)
single_f1_f2 <- feols(Y ~ X1 | f1 + f2, data = d)

# 2) csw (cumulative stepwise)
multi_csw <- feols(Y ~ X1 | csw(f1, f2), data = d)

# 3) sw (stepwise)
multi_sw <- feols(Y ~ X1 | sw(f1, f1 + f2), data = d)

cat("Model: Y ~ X1 | f1\n")
cat(sprintf("single: nobs=%d  nparams=%d  se=%.10f\n", single_f1$nobs, single_f1$nparams, summary(single_f1)$se["X1"]))
cat(sprintf("csw: nobs=%d  nparams=%d  se=%.10f\n", multi_csw[[1]]$nobs, multi_csw[[1]]$nparams, summary(multi_csw[[1]])$se["X1"]))
cat(sprintf("sw: nobs=%d  nparams=%d  se=%.10f\n", multi_sw[[1]]$nobs,  multi_sw[[1]]$nparams, summary(multi_sw[[1]])$se["X1"]))

#> Model: Y ~ X1 | f1
#> single: nobs=100  nparams=6  se=0.1227675080
#> csw: nobs=100  nparams=6  se=0.1227675080
#> sw: nobs=100  nparams=7  se=0.1234257835

cat("\nModel: Y ~ X1 | f1 + f2\n")
cat(sprintf("single: nobs=%d  nparams=%d  se=%.10f\n", single_f1_f2$nobs,   single_f1_f2$nparams, summary(single_f1_f2)$se["X1"]))
cat(sprintf("csw: nobs=%d  nparams=%d  se=%.10f\n", multi_csw[[2]]$nobs, multi_csw[[2]]$nparams, summary(multi_csw[[2]])$se["X1"]))
cat(sprintf("sw: nobs=%d  nparams=%d  se=%.10f\n", multi_sw[[2]]$nobs,  multi_sw[[2]]$nparams, summary(multi_sw[[2]])$se["X1"]))

#> Model: Y ~ X1 | f1 + f2
#> single: nobs=100  nparams=9  se=0.1288801690
#> csw: nobs=100  nparams=9  se=0.1288801690
#> sw: nobs=100  nparams=10  se=0.1295941920

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions