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.
`2SLS` <- model_2
) – Parliamentarianismlm()
object. Thanks! – Lexicology