0

It appears that the stargazer package's "Observations" is incorrect if factor interactions are dropped from a model:

Here's the issue using R's built-in dataset:

data(mtcars)
names(mtcars)
mtcars$gear.f = as.factor(mtcars$gear) # create two sets of factors
mtcars$carb.f = as.factor(mtcars$carb)

fit.1 <- lm(mpg ~ gear.f*carb.f, data=mtcars)
stargazer(fit.1) # Observations is listed as 39 instead of 32

Does anyone know why this happens or how to sidestep it?

Thomas
  • 43,637
  • 12
  • 109
  • 140
Bryan
  • 1,771
  • 4
  • 17
  • 30
  • This is a guess, but as fit.1 <- lm(mpg ~ gear.f+carb.f, data=mtcars); stargazer(fit.1) gives 32 obs as expected and fit.1 <- lm(mpg ~ gear.f+carb.f*vs, data=mtcars) gives 36, it look as the number of observations is calculated by the number of estimates + the df. Id suggest to look at the code to check this. – user20650 Feb 16 '14 at 02:27
  • 4
    Line 2572 of stargazer-internal.r is return(as.vector(object.name$df.residual+length(object.name$coefficients))) to calculate the number of observations. So you could update this yourself or ask the package maintainer to confirm the issue. – user20650 Feb 16 '14 at 02:39
  • stargazer developer here. Yes, I confirm this is the issue for 4.5.3. I am currently testing a new release in which the problem will be fixed. –  Feb 27 '14 at 16:08

1 Answers1

1

This issue has been fixed in the latest release of stargazer (version 5.0), now available on CRAN.