[英]Bug? Stargazer fails to properly display fixed effects/factor labels with “omit” options?
當我在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”行中的標簽應為“是”。 這是錯誤嗎?
簡短的答案是它是一個錯誤。 看來,代碼的意圖是創建一個看起來像
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
當參數由矩陣和向量的混合組成時,結果的列數(行)由矩陣參數的列數(行)確定。 任何向量都會對其值進行循環或子集化以達到此長度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.