将列表中的 probitmfx 输出提供给 Stargazer

Feeding probitmfx output in a list to Stargazer

类似,我运行使用tidyr对子组(年份和组的所有组合)进行了一系列回归。

year <- rep(2014:2015, length.out = 10000)
group <- sample(c(0,1,2,3,4,5,6), replace=TRUE, size=10000)
value <- sample(10000, replace = T)
female <- sample(c(0,1), replace=TRUE, size=10000)
smoker <- sample(c(0,1), replace=TRUE, size=10000)

dta <- data.frame(year = year, group = group, value = value, female=female, smoker = smoker)

library(dplyr)
library(broom)
library(stargazer)

# create list of dfs
table_list <- dta %>%
    group_by(year, group) %>%
    group_split()

# apply the model to each df and produce stargazer result
model_list <- lapply(table_list, function(x) probitmfx(smoker ~ female, data = x))
stargazer(model_list, type = "text")

我收到一条错误消息

% Error: Unrecognized object type.

有人知道我该如何解决这个问题吗?

正如 Colin 在评论中指出的那样,stargazer 似乎不支持这种类型的模型。但是,modelsummary package 开箱即用地支持它(免责声明:我是作者)。

您可以完全省略 output 参数以获得漂亮的 HTML table,或者更改它以将您的 table 保存到 LaTeX、Word 或许多其他格式。

# Code from the original question
library(mfx)
library(dplyr)

year <- rep(2014:2015, length.out = 10000)
group <- sample(c(0,1,2,3,4,5,6), replace=TRUE, size=10000)
value <- sample(10000, replace = T)
female <- sample(c(0,1), replace=TRUE, size=10000)
smoker <- sample(c(0,1), replace=TRUE, size=10000)
dta <- data.frame(year = year, group = group, value = value, female=female, smoker = smoker)
table_list <- dta %>%
    group_by(year, group) %>%
    group_split()

model_list <- lapply(table_list, function(x) probitmfx(smoker ~ female, data = x))

# New code
library(modelsummary)
modelsummary(model_list, output = "markdown")
Model 1 Model 2 Model 3 Model 4 Model 5 Model 6 Model 7 Model 8 Model 9 Model 10 Model 11 Model 12 Model 13 Model 14
female 0.022 -0.026 -0.033 0.013 -0.030 -0.001 -0.003 -0.073 0.006 -0.041 0.075 -0.006 -0.009 0.023
(0.039) (0.038) (0.036) (0.037) (0.037) (0.038) (0.037) (0.038) (0.036) (0.038) (0.037) (0.038) (0.037) (0.038)
Num.Obs. 670 688 761 727 740 675 739 688 751 703 733 710 737 678
AIC 932.4 957.3 1058.1 1009.6 1029.2 939.7 1027.6 953.8 1044.9 977.4 1016.0 988.2 1025.6 943.5
BIC 941.4 966.4 1067.4 1018.8 1038.4 948.7 1036.8 962.9 1054.1 986.5 1025.2 997.4 1034.8 952.5
Log.Lik. -464.206 -476.648 -527.074 -502.806 -512.588 -467.837 -511.809 -474.924 -520.425 -486.682 -506.004 -492.123 -510.810 -469.740