5

Is it possible to change the default of stargazer so that it displays some custom model shortcut instead of the model number?

I found the model.number parameter but this is a on-/off parameter.

Ideally, I could pass something like model.names=c("hhc", "dca", "bpc") to stargazer and this would replace the automatic numbering.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103

2 Answers2

10

At the moment you could get your desires under the condition that those were the names of the model-objects, but not if they had other names, by doing this:

stargazer( hhc,dca,bpc, object.names=TRUE, model.numbers=FALSE)

This was tested with the first example in the help page:

stargazer(linear.1, linear.2, probit.model, title="Regression Results", type="text", object.names=TRUE,model.numbers=FALSE)

If on the other hand they had different names, then I think you need to hack the code so that the first few lines of the function body look like this:

stargazer2 <- function( #omit argument list which should remain untouched

  if( length(object.names) > 1 ){ 
            dots <- list(...)
            names(dots) <- object.names; 
            object.names=TRUE }
    save.warn.option <- getOption("warn")
    options(warn = -1)
    return(.stargazer.wrap(dots, type = type, title = title, style = style, 
        summary = summary, out = out, out.header = out.header, 
        # omitted the rest of the argument list....

And also set the environment of stargazer2 so it can find .stargazer.wrap

environment(stargazer2) <- environment(stargazer)
stargazer2(linear.1, linear.2, probit.model, title="Regression Results", 
            type="text", model.names=c("test1","test2","test3"))
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • ha, setting the `environment` - i have generally gone through the code imputing `:::` in such cases - this is so much easier, thanks – user20650 Dec 28 '14 at 00:30
  • 1
    The strategy of setting the environment protects you from repeatedly getting errors when there are multiple instances of function calls to non-exported functions. – IRTFM Dec 28 '14 at 02:52
6

You can now use column.labels to name each column as desired.

In your case that would be:

stargazer( hhc,dca,bpc, column.labels=c("hhc", "dca", "bpc"), model.numbers=FALSE)

vcvd
  • 422
  • 2
  • 7
  • 13