问题
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!
回答1:
This is possible, but you will have to edit the source code of the stargazer function:
- Access the edit-screen of the stargazer function with
trace(stargazer:::.stargazer.wrap, edit = T)
- Go to line 7103/7104 (may be different depending on your stargazer
version) 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 <- "]"
- Confirm with "save".
- 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
回答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)
来源:https://stackoverflow.com/questions/42995868/r-stargazer-package-eliminate-t-label-from-reported-test-statistics