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 TRUE
or 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?
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,...
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With