1

I have a modelsummary of three fixed effects regressions like so:

remotes::install_github("lrberge/fixest")
remotes::install_github("vincentarelbundock/modelsummary")

library(fixest)
library(modelsummary)

mod1 <- feols(mpg ~ hp | cyl, data = mtcars)
mod2 <- feols(mpg ~ wt | cyl, data = mtcars)
mod3 <- feols(mpg ~ drat | cyl, data = mtcars)

modelsummary(list(mod1, mod2, mod3), output = "markdown")
Model 1 Model 2 Model 3
hp -0.024
(0.015)
wt -3.206
(1.188)
drat 1.793
(1.564)
Num.Obs. 32 32 32
R2 0.754 0.837 0.745
R2 Adj. 0.727 0.820 0.718
R2 Within 0.080 0.392 0.048
R2 Within Adj. 0.047 0.371 0.014
AIC 167.9 154.6 169.0
BIC 173.8 160.5 174.9
RMSE 2.94 2.39 2.99
Std.Errors by: cyl by: cyl by: cyl
FE: cyl X X X

Instead of having the table show merely whether certain fixed effects were present, is it possible to show the number of fixed effects that were estimated instead?

The raw models do contain this information:

> mod1
OLS estimation, Dep. Var.: mpg
Observations: 32 
Fixed-effects: cyl: 3
Standard-errors: Clustered (cyl) 
    Estimate Std. Error  t value Pr(>|t|) 
hp -0.024039   0.015344 -1.56664  0.25771 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RMSE: 2.94304     Adj. R2: 0.727485
                Within R2: 0.07998 
RoyalTS
  • 9,545
  • 12
  • 60
  • 101

1 Answers1

1

Yes, you’ll need to define a glance_custom.fixest() method. See this section of the docs for detailed instructions and many examples:

https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#customizing-existing-models-part-i

And here’s an example with fixest:

library(fixest)
library(tibble)
library(modelsummary)

models <- list(
    feols(mpg ~ hp | cyl, data = mtcars),
    feols(mpg ~ hp | am, data = mtcars),
    feols(mpg ~ hp | cyl + am, data = mtcars)
)

glance_custom.fixest <- function(x, ...) {
    tibble::tibble(`# FE` = paste(x$fixef_sizes, collapse = " + "))
}

modelsummary(models, gof_map = c("nobs", "# FE"))
(1) (2) (3)
hp -0.024 -0.059 -0.044
(0.015) (0.000) (0.016)
Num.Obs. 32 32 32
# FE 3 2 3 + 2
Vincent
  • 15,809
  • 7
  • 37
  • 39
  • Oh excellent! Any way I can retain one row for each separate fixed effect, with the number of levels for each FE in the cell bodies? – RoyalTS Jan 25 '23 at 21:04
  • Well, you can do whatever you want by changing the `glance_custom.fixest` function and adding new columns to the output data frame, but you'll have to look at the structure of the `fixest` object to identify exactly the info you want/need: `str(model)` – Vincent Jan 25 '23 at 21:09