Building on Constantin's helpful answer, I created a simple function unzelig
to take a glm zelig object and return a conventional glm object:
# extract data + model + family zelig object, return glm object
unzelig <- function(zelig_model) {
z_out <- zelig_model$zelig.out$z.out[[1]]
z_family <- z_out[["family"]][["family"]]
# when zelig(model = 'ls') assign family <- "gaussian"
if(is.null(z_family)) {z_family <- "gaussian"}
glm(z_out,
family = z_family)
}
# simple example
z1 <- zelig(mpg ~ cyl, model = 'ls', data = mtcars, cite = FALSE)
z2 <- zelig(I(mpg > 15) ~ cyl, model = 'logit', data = mtcars, cite = FALSE)
z3 <- zelig(as.integer(mpg) ~ cyl, model = 'poisson', data = mtcars, cite = FALSE)
g1 <- unzelig(z1)
g2 <- unzelig(z2)
g3 <- unzelig(z3)
stargazer(g1, g2, g3, type = 'text')
# error check
g1 <- glm(mpg ~ cyl, data = mtcars)
g2 <- glm(I(mpg > 15) ~ cyl, family = binomial, data = mtcars)
g3 <- glm(as.integer(mpg) ~ cyl, family = poisson, data = mtcars)
stargazer(g1, g2, g3, type = 'text')
Also, there's an in-development function to convert some non-Zelig objects to Zelig-friendly objects with a command to_zelig
. This would allow estimating a model with standard R functions like lm
or glm
, using stargazer
or another package to generate a table and then converting the object to use Zelig
functions like setx
and sim
. See more, here:
http://docs.zeligproject.org/reference/to_zelig.html