2

I want to format multiple univariate model outputs on top of one another using stargazer (with the same dependent variable), and I can't get them to not show up side-by-side.

data(iris)
stargazer(multinom(Species ~ Sepal.Length, data = iris),
          multinom(Species ~ Sepal.Width, data = iris),
          type = "text", apply.coef = exp, p.auto = FALSE, omit = "Constant")

Which gives the following output:

============================================================
                             Dependent variable:            
                  ------------------------------------------
                  versicolor virginica  versicolor virginica
                     (1)        (2)        (3)        (4)   
------------------------------------------------------------
Sepal.Length      123.479*** 941.955***                     
                   (0.907)    (1.022)                       

Sepal.Width                              0.002***  0.017*** 
                                         (0.991)    (0.844) 

------------------------------------------------------------
Akaike Inf. Crit.  190.068    190.068    260.537    260.537 
============================================================
Note:                            *p<0.1; **p<0.05; ***p<0.01

Rather than having "versicolor" and "virginica" repeated twice for the different models, I just want each of them once, with the different model predictors and estimates underneath one another.

Is there any way of doing this?

T.P.
  • 87
  • 1
  • 6
  • What do you want the model statistics to look like? In your example Akaike is different for each model. How should this be displayed? Side-by-side is the standard format. – Marco Dec 04 '19 at 07:48

1 Answers1

4

starpolishr can do the job of panel format model outputs, but only for latex objects and only for equal model statistics.

install.packages("remotes")
remotes::install_github("ChandlerLutz/starpolishr")

## -- Regressoin example -- ##
library(stargazer)
data(mtcars)
##First set up models without weight
mod.mtcars.1 <- lm(mpg ~ hp, mtcars)
mod.mtcars.2 <- lm(mpg ~ hp + cyl, mtcars)
star.out.1 <- stargazer(mod.mtcars.1, mod.mtcars.2, keep.stat = "n")
##Second set of models with weight as a regressor
mod.mtcars.3 <- lm(mpg ~ hp + wt, mtcars)
mod.mtcars.4 <- lm(mpg ~ hp + cyl + wt, mtcars)
star.out.2 <- stargazer(mod.mtcars.3, mod.mtcars.4, keep.stat = c("n", "rsq"))

##stargazer panel -- same summary statistics across panels.
star.panel.out <- star_panel(star.out.1, star.out.2,
                             panel.names = c("Without Weight", "With Weight")
)
print(star.panel.out)

Here you have to remove quotation marks and line numbering, and can compile as .tex Output looks like this:

enter image description here

It's still kind of a workaround and I cannot figure out a visual benefit of alignment model outputs in vertical/panel format. What you usually do is landscape your side-by-side tables in your final document.

Marco
  • 2,368
  • 6
  • 22
  • 48