I want to compare the results of different models (lm, glm, plm, pglm) in a table in R using stargazer or a similar tool. However I can't find a way to display the coefficients in scientific notation. This is kind of a problem because the intercept is rather large (about a million) while other coefficients are small (about e-7) which results in lots of useless zeros making it harder to read the table.
I found a similar question here: Format model display in texreg or stargazer R as scientific. But the results there require rescaling the variables and since I use count data I wouldn't want to rescale it.
I am grateful for any suggestions.
Here's a reproducible example:
m1 <- lm(Sepal.Length ~ Petal.Length*Sepal.Width,
transform(iris, Sepal.Length = Sepal.Length+1e6,
Petal.Length=Petal.Length*10, Sepal.Width=Sepal.Width*100))
# Coefficients:
# (Intercept) Petal.Length Sepal.Width Petal.Length:Sepal.Width
# 1.000e+06 7.185e-02 8.500e-03 -7.701e-05
I don't believe stargazer
has easy support for this.
You could try other alternatives like xtable
or any of the many options here (I have not tried them all)
library(xtable)
xtable(m1, display=rep('g', 5)) # or there's `digits` too; see `?xtable`
Or if you're using knitr
or pandoc
I quite like pander
, which has automagic scientific notation already (note: this is pandoc output which looks like markdown, not tex output, and then you knit or pandoc to latex/pdf):
library(pander)
pander(m1)