1

Similarly to here, I am running a series of regressions on subgroups (all combinations of year and group) using 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")

I get an error saying

% Error: Unrecognized object type.

Anybody know how I can get around this issue?

Vincent
  • 15,809
  • 7
  • 37
  • 39
Stata_user
  • 562
  • 3
  • 14
  • 1
    This just means `probitmfx` objects aren't supported by `stargazer`. There's a list of supported packages starting on page 9 of the vignette: [https://cran.r-project.org/web/packages/stargazer/vignettes/stargazer.pdf](https://cran.r-project.org/web/packages/stargazer/vignettes/stargazer.pdf) – Colin H Feb 16 '21 at 18:13

1 Answers1

3

As Colin noted in the comments, this type of model does not appear to be supported by stargazer. However, it is supported out-of-the-box by the modelsummary package (disclaimer: I am the author).

You can omit the output argument altogether to get a nice HTML table, or change it to save your table to LaTeX, Word, or lots of other formats.

# 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
Vincent
  • 15,809
  • 7
  • 37
  • 39