Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom model names in Stargazer package for R

I'm wondering how to get custom model names in the stargazer package for R.

There is an option for model.names which can be set to TRUEor FALSE, but it does not support a vector or names such as model.names = c('OLS','2SLS','GLS').

Is there any way to override the function to use custom names passed as parameters instead of reading the model names from the objects passed?

like image 477
Nicolas Avatar asked Dec 29 '15 18:12

Nicolas


People also ask

What is Stargazer in R?

stargazer is a new R package that creates LaTeX code for well-formatted regression tables, with multiple models side-by-side, as well as for summary statistics tables. It can also output the content of data frames directly into LaTeX. Compared to available alternatives, stargazer excels in three regards: its ease of use,...

What is the Stargazer command?

The stargazer command produces LaTeX code, HTML code and ASCII text for well-formatted tables that hold regression analysis results from several models side-by-side. It can also output summary statistics and data frame content. stargazer supports a large number model objects from a variety of packages. Please see stargazer models.

How does Stargazer compare to other alternatives?

Compared to available alternatives, stargazer excels in three regards: its ease of use, the large number of models it supports, and its beautiful aesthetics. stargazer was designed with the user’s comfort in mind.

What is z-scores in Stargazer?

a logical value that indicates whether stargazer should calculate the test statistics (i.e., the z-scores) automatically if coefficients or standard errors are supplied by the user (from arguments coef and se) or modified by a function (from arguments apply.coef or apply.se ). If FALSE, the package will use model's default values if t is NULL.


1 Answers

Stargazer optionally includes the object names, so if you models are

m1 = lm(mpg ~ wt, data = mtcars)
m2 = lm(mpg ~ wt + disp, data = mtcars)

You can do

stargazer(m1, m2, object.names = TRUE,
          column.labels = c("lab 1", "lab 2e"))

to get both custom labels and the object names, m1 and m2. This can be usefully abused by using non-standard names matching the extra model names that you want

OLS = m1
`2SLS` = m2
    stargazer(OLS, `2SLS`, object.names = TRUE,
              column.labels = c("lab 1", "lab 2e"))

Though, unfortunately, the backticks are included in the output. (As an additional hack you could capture.output() and remove them with gsub).

The model names used by stargazer are not part of the model object, rather stargazer examines the model object and attempts to extract them. You can see the .model.identify function on github. You could attempt to fixInNamespace to adjust this, but I think a post-hoc hack is easier.

like image 89
Gregor Thomas Avatar answered Sep 20 '22 09:09

Gregor Thomas