2

I am trying to create a summary statistics table with Stargazer with some large variables (mean>1000) and some smaller ones (<1). The problem is that I don't want decimals on the larger numbers, only on the smaller ones. I tried using digits.extra, but it did not appear to work.

Problem:

test<-data.frame(a=c(0.3, 0.45),b=c(3320,2583))
stargazer(test, type='text', omit.summary.stat = c("p25", "p75"))

==========================================
Statistic N   Mean    St. Dev.  Min   Max 
------------------------------------------
a         2   0.375    0.106   0.300 0.450
b         2 2,951.500 521.138  2,583 3,320
------------------------------------------

Code I hoped would work:

stargazer(test, type='text', omit.summary.stat = c("p25", "p75"), digits=0, digits.extra = 3)

 ======================================
 Statistic N Mean  St. Dev.  Min   Max 
 --------------------------------------
 a         2   0      0       0     0  
 b         2 2,952   521    2,583 3,320
 --------------------------------------

What I want:

==========================================
Statistic N   Mean    St. Dev.  Min   Max 
------------------------------------------
a         2 0.375    0.106   0.300 0.450
b         2 2,952    521     2,583 3,320
------------------------------------------

Is there a way to make this happen?

winitheju
  • 65
  • 1
  • 7
  • 1
    not sure if helpful: https://stackoverflow.com/questions/40015431/r-stargazer-different-decimals – Ben Jun 29 '19 at 20:39

2 Answers2

0

@Ben's comment looks useful, but I think your situation is a little bit different because stargazer is computing the summary for you and not putting a summary into stargazer.

This does appear difficult because the digits argument applies over all the columns. Have you considered splitting up your dataframe into small and large? This might make more sense to the reader anyway.

Here's my attempt for you.

test<-data.frame(a=c(0.3, 0.45),b=c(3320,2583),c=c(0.2, 0.35),d=c(2320,1583))
test

mean_calc <- apply(test,2,mean)

ind <- mean_calc < 1 #Create an index of small means

small <- test[,ind] #Separate dataset into small means
large <- test[,!ind] #Separate dataset into large means

Create two different stargazer outputs.

stargazer(small, type='text', omit.summary.stat = c("p25", "p75"), digits=3)
stargazer(large, type='text', omit.summary.stat = c("p25", "p75"), digits=0)

I know this isn't exactly what you were looking for, but maybe it will help.

Scott Hunter
  • 254
  • 2
  • 14
0

If the problem is just that the table is too wide to fit the page, it might be sufficient to set the argument "column.sep.width" of the stargazer() function to a negative value, e.g.

column.sep.width = "-5pt"
umor
  • 1
  • 1