user5457414
user5457414

Reputation: 137

Stargazer printing zeros instead of my data

I made a dataset and I'm trying to get Stargazer to print it as is, but for the last column it won't print anything but zeros.

my_object<-structure(list(labels_for_t_test = structure(c(4L, 3L, 2L, 1L), 
                .Label = c("% who report excessive drinking", "% with a BMI 30 or above", "Mentally unhealthy days per month", 
                           "Physically unhealthy days per month"), class = "factor"), 
                           `estimate.mean of x` = c(3.81651019006183,3.45526222746022, 30.4518625528841, 14.7764967356577), 
                           `estimate.mean of y` = c(3.69675958188153, 3.5731520223152, 28.8823529411765, 15.6045118082481), 
                            statistic.t = c(6.41504498947883, -6.74576716155339, 17.0617198661627, -8.02284265433504), 
                            p.value = c(1.48603650334571e-10, 1.62589843848316e-11, 3.19751229848406e-63, 1.19147131984837e-15)), 
                            .Names = c("labels_for_t_test", "estimate.mean of x", "estimate.mean of y", "statistic.t", "p.value"), 
                            row.names = c("Physically.Unhealthy.Days", "Mentally.Unhealthy.Days", "X..Obese", "X..Excessive.Drinking"), class = "data.frame")
                                                                                                                                                                                                 -6.74576716155339, 17.0617198661627, -8.02284265433504), p.value = c(1.48603650334571e-10, 
stargazer(my_object, title="Results of Welch Two Sample t-tests Comparing Counties with 10 or More Gun Deaths and Counties with Fewer", 
      digits=15, digits.extra= 100, type="html", rownames = FALSE,
      out="t tests test.html", summary = FALSE,
      covariate.labels = c("Variable","--mean for >=10 gun deaths--", "--mean for <10--", "t-statistic", "p-value"))

I've run this with digits=100 and it still doesn't show anything but a single zero in the p-value column. I would ideally like to print the p-values in scientific notation, but if it's not even recognizing the values at all that's obviously a bigger problem. I'm stumped, and I'd really appreciate any help!

Upvotes: 0

Views: 568

Answers (1)

MichaelChirico
MichaelChirico

Reputation: 34703

As I mentioned, I can't think of an outlet that would frown upon you for just saying p = 0 when your largest p-value is 1.48*10^-10.

But if you insist on printing in scientific notation, just convert that column before passing to stargazer:

my_object$p.value <- format(my_object$p.value, width = 4, digits = 3)

(feel free to play with the parameters...)

Then stargazer should work as expected.

Upvotes: 1

Related Questions