r - 漏洞? Stargazer 无法使用 "omit"选项正确显示固定效应/因子标签?

标签 r stargazer

当我在 stargazer 中生成一个表并忽略固定效果,然后指定 omit.labels 选项时,stargazer(版本 5.2.2)对每个显示“否”柱子。这是一个例子:

library(stargazer)

# generate example data
set.seed(1)
list_of_states <- rep(c(1, 2, 3, 4, 5), 5)
df <- data.frame("state" = list_of_states, "y" = runif(25),
    "x1" = runif(25), "x2" = runif(25))

# OLS without fixed effects
ols.1 <- glm(y ~ x1, data = df)
ols.2 <- glm(y ~ x1 + x2, data = df)

# OLS with fixed effects
fe.1 <- glm(y ~ x1 + factor(state), data = df)
fe.2 <- glm(y ~ x1 + x2 + factor(state), data = df)

stargazer(ols.1, ols.2, fe.1, fe.2,
  type = "text",
  align = TRUE,
  omit = c("state"),
  omit.labels = c("State FE"))

这输出

==================================================
                        Dependent variable:       
                  --------------------------------
                                 y                
                    (1)      (2)     (3)     (4)  
--------------------------------------------------
x1                 0.088    0.098   0.151   0.157 
                  (0.241)  (0.264) (0.263) (0.283)

x2                          0.028           0.022 
                           (0.270)         (0.287)

Constant          0.485*** 0.467*  0.466**  0.452 
                  (0.142)  (0.227) (0.215) (0.280)

--------------------------------------------------
State FE             No      No      No      No   
--------------------------------------------------
Observations         25      25      25      25   
Log Likelihood     -5.321  -5.315  -3.528  -3.524 
Akaike Inf. Crit.  14.642  16.630  19.056  21.048 
==================================================
Note:                  *p<0.1; **p<0.05; ***p<0.01

“状态 FE”行中的标签应在最后两列中显示"is"。这是错误吗?

最佳答案

简短的回答是这是一个错误。看起来代码的目的是创建一个看起来像的矩阵

cbind(names(coef(ols.1)), names(coef(fe.1)))
#      [,1]          [,2]            
# [1,] "(Intercept)" "(Intercept)"   
# [2,] "x1"          "x1"            
# [3,] "(Intercept)" "factor(state)2"
# [4,] "x1"          "factor(state)3"
# [5,] "(Intercept)" "factor(state)4"
# [6,] "x1"          "factor(state)5"

然后检查每列是否有 omit 正则表达式。然而,实际发生的事情是这样的

cbind(cbind(NULL, names(coef(ols.1))), names(coef(fe.1)))
#      [,1]          [,2]         
# [1,] "(Intercept)" "(Intercept)"
# [2,] "x1"          "x1"  

这导致找不到 omit 项。发生这种情况是因为,从 ?cbind

When the arguments consist of a mix of matrices and vectors the number of columns (rows) of the result is determined by the number of columns (rows) of the matrix arguments. Any vectors have their values recycled or subsetted to achieve this length.

关于r - 漏洞? Stargazer 无法使用 "omit"选项正确显示固定效应/因子标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53026337/

相关文章:

regex - 在 R 统计中创建正则表达式

c - 从源代码构建 R 包 krb5

r - 如何区分应用程序崩溃和用户关闭

r - 如何为每列制作因变量标签 Stargazer

stargazer:F Statistic/df 中的换行符

r - Leaflet R中的分组图层控制

r - 与 as.POSIXct 相比,为什么 lubridate 函数如此慢?

r - 键入 ="latex"时如何将观星表向左对齐?

Stargazer Rmarkdown : LaTeX Error if align is set to TRUE

r - 是否有自动显示 `stargazer` 表中回归 F 统计量的 p 值的方法?