0

Sometimes it's tacky to include statistical significance stars for the constant term when reporting the results of a regression. Is it possible to configure stargazer to keep stars for the regressors, but not for the constant term?

fit <- lm(rating ~ complaints, data=attitude)
stargazer(fit)
Alex Coppock
  • 2,122
  • 3
  • 15
  • 31

2 Answers2

1

Basically, the answer turned out to be using stargazer's p argument. From there, I just needed to write a (series of) function(s) that took a list of regression fits and returned a list of vectors of p-values. I then manually changed the p-value of the intercepts to be 1, and presto, no tacky stars on the intercept. Plus it's reproducible with no manual LaTeX editing!

commarobust <- function(fit){
  require(sandwich)
  require(lmtest)
  coeftest(fit,vcovHC(fit, type="HC2"))
}

getrobustps <- function(fit){
  robustfit <- commarobust(fit)
  ps <- robustfit[,4]
  ps["(Intercept)"] <- 1
  return(ps)
}

makerobustpslist <- function(fitlist){
  return(lapply(fitlist, FUN=getrobustps) )
}

Then in the stargazer call:

stargazer(fit_1, fit_2, fit_3, fit_4, fit_5, 
          p=makerobustpslist(list(fit_1, fit_2, fit_3, fit_4, fit_5)))

Works like a charm.

Alex Coppock
  • 2,122
  • 3
  • 15
  • 31
0

You could alternatively use the broom package to convert the fit results to a data frame, and then add stars to your heart's content:

library("broom")
mod <- lm(mpg ~ wt + qsec, data = mtcars)
DF <- tidy(mod)
DF$stars <- c("", "***", "***") # inspect and add manually, or automate

And the xtable package could be used to format it for LaTeX or whatever.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
  • The default for stargazer is Latex. The OP should say why he cannot just edit the HTML or Latex output. – IRTFM Apr 07 '15 at 00:18
  • Manually editing the LaTeX output is a last-ditch solution (that I might end up using) but it is not ideal -- mostly because the tables are not directly reproducible from the code. – Alex Coppock Apr 07 '15 at 02:06