问题描述
与 here 类似,我正在使用 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),size=10000)
smoker <- sample(c(0,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 表格,或者更改它以将您的表格保存为 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),size=10000)
smoker <- sample(c(0,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")
模型1 | 模型2 | 模型3 | 模型 4 | 模型5 | 模型6 | 模型 7 | 模型8 | 模型 9 | 模型 10 | 模型11 | 模型12 | 模型 13 | 模型 14 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
女性 | 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 |