R stargazer package: eliminate "t =" label from reported test statistics
Asked Answered
M

2

9

I am currently preparing a table of regression results with stargazer. In this, I also want to show the t-statistics. For that, I use the following simplified specification, as also shown in http://jakeruss.com/cheatsheets/stargazer.html#report-t-statistics-or-p-values-instead-of-standard-errors

stargazer(output, output2, type = "html",
      report = "vc*t")

The resulting table reports the t-statistics as follows:

0.088    
t = 5.822***

Now my question: the "t =" is repeated for each model and each coefficient. This is somehow redundant and reduces readability of the table.

Is there a way to only report the value for t-statistic without the "t =" label? It would be great to just show the value in parentheses.

Thanks!

Moritz answered 24/3, 2017 at 9:33 Comment(0)
V
10

This is possible, but you will have to edit the source code of the stargazer function:

  1. Access the edit-screen of the stargazer function with trace(stargazer:::.stargazer.wrap, edit = T)
  2. Go to line 7103/7104 (may be different depending on your stargazer version, e.g., its now lines 7053 and 7054 for version 5.2.2. in April 2021) and look for .format.t.stats.left <- "t = " and .format.t.stats.right <- "" and edit it to your liking, e.g., .format.t.stats.left <- "[" and .format.t.stats.right <- "]"
  3. Confirm with "save".
  4. You will have to redo this step every time you restart your R session as the changes to the source code are only temporarily.

Your stargazer output of stargazer(model1, type = "text", report = "vc*t")should then look like the following:

=======================================================================
                                         Dependent variable:           
                              -----------------------------------------
                                           daily_invcount2             
                                              negative                 
                                              binomial                 
-----------------------------------------------------------------------
log(lag_raised_amount + 1)                    -0.466***                
                                              [-7.290]                 
                                                                       
lag_target1                                   -0.661***                
                                              [-7.680]                 
                                                                                                                                                              
Constant                                      -3.480**                 
                                              [-5.490]                 
               
-----------------------------------------------------------------------
Observations                                    6,513                  
Log Likelihood                                 -8,834                
theta                                     1.840*** (0.081)             
Akaike Inf. Crit.                              17,924                
=======================================================================
Note:                         + p<0.1; * p<0.05; ** p<0.01; *** p<0.001
Victory answered 25/4, 2017 at 10:0 Comment(3)
Great answer, but is there a way to apply changes permanently, unless user updates the package?Ribband
Thanks. Not really - at least as far as I know. This answer: https://mcmap.net/q/408345/-modify-package-function provides some ideas on how to write a custom function and then overwriting the existing function with this one.Victory
Updating this on April 2021: the lines to change are 7053 and 7054 if you are on stargazer 5.2.2.Kaz
C
2

A workaround is to capture the stargazer output and edit it. Here is an example where I save the stargazer output to a file, and then edit out "t = " from that file.

stargazer.save <- function(f.out, ...) {
# This is a wrapper function for saving stargazer output to file
output <- capture.output(stargazer(...))
cat(paste(output, collapse = "\n"), "\n", file=f.out, append=TRUE)
}

#save stargazer output (to e.g. a tex file)
stargazer.save(outfile, model.fit, report = "vc*t")

# read file back into R
u = readChar(outfile, file.info(outfile)$size)

# replace "t = " with a blank space
u = gsub("t = ","", u, ignore.case = F)

#write back to file
cat(u, file = outfile, append = F)
Cenogenesis answered 22/5, 2018 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.