r - 在fixst::etable()中对固定效果进行分组

标签 r

在报告 fixest 回归的结果时,我想通过在同一行中报告多个 FE 来节省空间。查看trade数据,这是一个简单的示例:

data(trade)
est_1 <- feols(Euros ~ log(dist_km) | Origin + Destination + Product, trade)

etable 产生我们期望的结果:

> etable(est_1)
                                          est_1
Dependent Var.:                           Euros
                                               
log(dist_km)    -66,710,904.2*** (14,306,388.4)
Fixed-Effects:   ------------------------------
Origin                                      Yes
Destination                                 Yes
Product                                     Yes
_______________  ______________________________
S.E.: Clustered                      by: Origin
Observations                             38,325
R2                                      0.30324
Within R2                               0.05559
> 

但我希望原产地、目的地和产品只是一行,名称如“原产地、目的地和产品 FE”。但是group(以及keepdrop)似乎不适用于固定效果:

> etable(est_1, group = list("Origin and Destination and Product FEs" = "Origin|Dest|Product"))
                                                                 est_1
Dependent Var.:                                                  Euros
                                                                      
log(dist_km)                           -66,710,904.2*** (14,306,388.4)
Origin and Destination and Product FEs                              No
Fixed-Effects:                          ------------------------------
Origin                                                             Yes
Destination                                                        Yes
Product                                                            Yes
______________________________________  ______________________________
S.E.: Clustered                                             by: Origin
Observations                                                    38,325
R2                                                             0.30324
Within R2                                                      0.05559

也就是说,group 生成的新行全部为 No,而旧的 FE 行仍然存在。如果我尝试通过在 setFixest_dict

中重复变量标签来欺骗 fixest
setFixest_dict(c(Origin = "Origin and Destination and Product FEs",
                 Destination = "Origin and Destination and Product FEs",
                 Product = "Origin and Destination and Product FEs"))

etable 明智地对我大喊非唯一的值。

(我在这里使用的贸易示例可能是一个糟糕的例子,但请考虑对某些待遇和一系列人口固定效应(年龄、性别、地区等)进行工资回归。在这种情况下,称为“人口统计 FE”的“是/否 FE”行(在表注释中进行适当解释)会很好。)

最佳答案

不太优雅,但您可以使用 etable() 返回的 data.frame。

library(fixest)
suppressMessages(library(dplyr))
data(trade)
est_1 <- feols(Euros ~ log(dist_km) | Origin + Destination + Product, trade)

# revemo all but first fixef_vars 
vars_to_remove <- est_1$fixef_vars[2:length(est_1$fixef_vars)]

# set a dict 
setFixest_dict(c(Origin = "Origin and Destination and Product FEs"))

# workd with data.frame
et <- etable(est_1)
et %>% filter(!rownames(et) %in% vars_to_remove)
#>                                                                  est_1
#> Dependent Var.:                                                  Euros
#>                                                                       
#> log(dist_km)                           -66,710,904.2*** (14,306,388.4)
#> Fixed-Effects:                          ------------------------------
#> Origin and Destination and Product FEs                             Yes
#> ______________________________________  ______________________________
#> S.E.: Clustered                                             by: Origin
#> Observations                                                    38,325
#> R2                                                             0.30324
#> Within R2                                                      0.05559

reprex package 于 2021 年 3 月 23 日创建(v1.0.0)

关于r - 在fixst::etable()中对固定效果进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66769523/

相关文章:

r - 无法将曲线拟合到数据集

r - 绘制项目图(基于难度)

r - 如何用 R 中的特定值替换 NA 值?

r - ggplot2:向 geom_line 添加点

R - 用特定符号分隔,垂直裸露,|

css - R Shiny : relative css size for plotOutput not working

r - 如何确保 RStudio 包含在 .bashrc 中所做的更改

R:更改空间点重叠的栅格值

r - foreach:保留名称

r - 如何在中断分段时间序列回归中向 ggplot 添加线性段