0

The stargazer package is rounding my regression output. For example, stargazer takes my regression coefficient of -3.56588 and outputs -3.600. Following a comment posted here, I attempted to resolve using digits=NA, however, received the following error:

Error in paste(first.part, .format.decimal.character, decimal.part, sep = "") : object 'decimal.part' not found.

Minimal working example with an error message as follows:

library(stargazer)
data(mtcars)

mylogit <- glm(vs ~ cyl + disp + hp, data = mtcars, family = "binomial")
summary(mylogit)
stargazer(mylogit, digits=NA) 

mylogit2 <- glm(vs ~ disp + hp + qsec, data = mtcars, family = "binomial")
summary(mylogit2)
stargazer(mylogit2, digits=NA)  

Interestingly, the output works correctly for mylogit but not for mylogit2!

Any thoughts would be greatly appreciated!

gravityflyer
  • 119
  • 5
  • 1
    Welcome to stackoverflow! By following this guide [how to ask](https://stackoverflow.com/help/how-to-ask) you provide a solid basis for answering this question. In particular, it's mostly necessary to provide an [verifiable example](https://stackoverflow.com/help/mcve) (a minimum, complete, and verifiable example). Check out [this page](https://stackoverflow.com/a/5963610/4573108) for tips regarding R-specific MCVEs. Good look and thank you for contributing! – mischva11 Apr 20 '19 at 19:50
  • @mischva11 Thank you for the reminder! Edited original post with minimal working example. Hope this is correct? Thanks! – gravityflyer Apr 21 '19 at 02:24
  • @gravityflyer While it's good that you've added code to your question, link to data is generally considered a poor way to share it. Please re-read the top answer in the last link in mischava11's comment. – Z.Lin Apr 21 '19 at 06:25

2 Answers2

1

Just in case anyone in the future encounters a similar problem, after much deliberation and frustration I decided to use the package texreg instead.

texreg function

Overall a very easy package to export Rstudio tables to LaTeX and, more importantly, does not cause any rounding issues.

gravityflyer
  • 119
  • 5
0

Old question, but I was having the same problem today and figured out a solution. My regression coefficients should have been 0.136, 0.244, etc. but were coming out in the Stargazer table as 0.140, 0.240...

Near the beginning of my rmarkdown document I had the command

options(digits=2)

I thought this just affected the number of digits displayed in the console. But no! It appears that Stargazer uses this rounded output. So changing the "digits" option to 3 in Stargazer does nothing except add a 0 to this 2-digit output.

The solution was to change the command at the beginning to

 options(digits=3)

and this fixed it! digits=7 is the default.

nate
  • 1
  • 3