Question

I just ran a series of models in a nice, flexible way that enforced data-code separation. I had a nice list of formulas and models in my configuration section which I lapply'd over to get a list of model objects. Now I want to display them in stargazer, but it doesn't take a list object. How do I do this without having to type out each list element?

Reproducible example:

require(stargazer)
l <- list()
l$lm1 <- lm(rating ~ complaints + privileges + learning + raises + critical,
data=attitude)
l$lm2 <- lm(rating ~ complaints + privileges + learning, data=attitude)
## create an indicator dependent variable, and run a probit model
attitude$high.rating <- (attitude$rating > 70)
l$prbt <- glm(high.rating ~ learning + critical + advance, data=attitude,
family = binomial(link = "probit"))
stargazer( l[[1]], l[[2]], l[[3]], title="Results", align=TRUE, type="text")
Was it helpful?

Solution

Please make sure you are using an up-to-date version of the package. Starting with version 4.5.3 (available on CRAN since Nov 2013), stargazer has been able to accept lists of object in exactly the way you would expect:

stargazer(l, title="Results", align=TRUE, type="text")

OTHER TIPS

Use do.call:

do.call( stargazer, l ) 

However, this precludes passing in arguments in the usual way:

> do.call( stargazer, l, type="text" )
Error in do.call(stargazer, l, type = "text") : 
  unused argument (type = "text")

Therefore, you have to add the named arguments to the list:

l$type <- "text"
l$align <- TRUE
l$title <- "Results"
do.call( stargazer, l )

Another way to do this is to curry the stargazer function:

require(functional)
sgCurried <- Curry( stargazer, type="text" ) # all arguments to stargazer go in here
do.call( sgCurried, l )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top