最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

r - How to display the number of groups in fixest regression tables using modelsummary? - Stack Overflow

programmeradmin5浏览0评论

I'm using the fixest package for fixed effects regressions and modelsummary to create tables. I'd like the tables to show the number of groups (e.g., number of unique values for the fixed effect variables). Here's a minimal example:

library(fixest)
library(modelsummary)

# Example fixed effects regression
reg1 <- feols(Sepal.Length ~
                Sepal.Width + Petal.Length + Petal.Width |
                Species,
              data = iris
)

# Create summary table
msummary(reg1)

This produces a nice table, but I'd like to add the number of groups in my fixed effect (in this example, it would be 3 species). I've tried using gof_map to include this information, but it doesn't seem to extract the number of groups by default:

msummary(reg1, 
         gof_map = c("nobs", "r.squared", "adj.r.squared", "n"))

Is there a way to make modelsummary display the number of groups for each fixed effect in my model? I'd prefer a solution that works with the standard modelsummary functionality, but I'm open to custom functions if needed.

Note: In my actual research, I'm working with panel data where the number of groups is important for interpreting the results.

I'm using the fixest package for fixed effects regressions and modelsummary to create tables. I'd like the tables to show the number of groups (e.g., number of unique values for the fixed effect variables). Here's a minimal example:

library(fixest)
library(modelsummary)

# Example fixed effects regression
reg1 <- feols(Sepal.Length ~
                Sepal.Width + Petal.Length + Petal.Width |
                Species,
              data = iris
)

# Create summary table
msummary(reg1)

This produces a nice table, but I'd like to add the number of groups in my fixed effect (in this example, it would be 3 species). I've tried using gof_map to include this information, but it doesn't seem to extract the number of groups by default:

msummary(reg1, 
         gof_map = c("nobs", "r.squared", "adj.r.squared", "n"))

Is there a way to make modelsummary display the number of groups for each fixed effect in my model? I'd prefer a solution that works with the standard modelsummary functionality, but I'm open to custom functions if needed.

Note: In my actual research, I'm working with panel data where the number of groups is important for interpreting the results.

Share Improve this question asked Mar 31 at 9:53 Laurence_jjLaurence_jj 7281 gold badge11 silver badges25 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You could use the gof_function argument to pull the `fixef_sizes` attribute from the model. For example, using the "mtcars" dataset:

mod = feols(mpg ~ disp | am + gear + carb, mtcars)
msummary(mod, gof_function=\(model) data.frame(t(model$fixef_sizes)))

      --- snip ---

发布评论

评论列表(0)

  1. 暂无评论