Skip to content

Instantly share code, notes, and snippets.

@cimentadaj
Last active September 22, 2016 18:04
Show Gist options
  • Save cimentadaj/e89bc2edc282e3f9158ba68c596a2d72 to your computer and use it in GitHub Desktop.
Save cimentadaj/e89bc2edc282e3f9158ba68c596a2d72 to your computer and use it in GitHub Desktop.
stargazer2 <- function(model, odd.ratio = F, ...) {
if(!("list" %in% class(model))) model <- list(model)
if (odd.ratio) {
coefOR2 <- lapply(model, function(x) exp(coef(x)))
seOR2 <- lapply(model, function(x) exp(coef(x)) * summary(x)$coef[, 2])
p2 <- lapply(model, function(x) summary(x)$coefficients[, 4])
stargazer(model, coef = coefOR2, se = seOR2, p = p2, ...)
} else {
stargazer(model, ...)
}
}
stargazer(m1, type = "text") # Our standard log odds
stargazer2(m1, odd.ratio = T, type = "text") # Now the coefficients and significance is correct!
# You can also use lists
m1 <- glm(mtcars$vs ~ mtcars$mpg)
m2 <- glm(mtcars$vs ~ mtcars$mpg + mtcars$hp)
m3 <- glm(mtcars$vs ~ mtcars$mpg + mtcars$hp + mtcars$am)
models <- list(m1, m2, m3)
stargazer(models, type = "text")
stargazer2(models, odd.ratio = T, type = "text")
# Same significance but different coefficients and SE's
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment