3

Please help resolve this error that I get when I execute the following:

stargazer(as.data.frame(st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)]), 
      type="html", 
      title="Mean and Standard Deviation of Monthly Household Income by State for Rural India (Unweighted)", 
      summary=F, covariate.labels=c("S.No.", "State", "Mean", "Std.Dev."), 
      digits=0,
      notes=c("Source: Periodic Labour Force Survey, 2017-18"), 
      out=c("tb2.state-rural.hh.earnings.html"))
Varun Nair
  • 33
  • 1
  • 3
  • 2
    Can you isolate the error? Is it in your subset code, does `st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)]` work? If that works, is it in the data frame conversion, does `as.data.frame(st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)])` work? If that works, then it must be in the `stargazer()` call. In that case, can does it work on the first 5 rows of data? Can you find a small subset of data that demonstrates the problem? And then share it in the question? – Gregor Thomas Oct 04 '22 at 15:25
  • No in both the cases, with or without the dataframe conversion, I'm getting the same error. I'm new to R.. I don't know how to obtain a smaller subset of the data that I'm using. Although I googled this issue and several people in reddit have mentioned that it is a stargazer package problem. It works when we assign it to an object – Varun Nair Oct 06 '22 at 03:06
  • Define `df = as.data.frame(st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)]` and then run `dput(df)` and put the results in the question. That will give us a copy/pasteable version of your data including in all class and structure information. – Gregor Thomas Oct 06 '22 at 13:39

2 Answers2

5

I had a similar problem. For me, it helped to define the data frame outside of the stargazer function. So it would be

df <- as.data.frame(st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)])
stargazer(df, 
      type="html", 
      title="Mean and Standard Deviation of Monthly Household Income by State for Rural India (Unweighted)", 
      summary=F, covariate.labels=c("S.No.", "State", "Mean", "Std.Dev."), 
      digits=0,
      notes=c("Source: Periodic Labour Force Survey, 2017-18"), 
      out=c("tb2.state-rural.hh.earnings.html"))

I'm not sure, however, if it also helps with your problem.

Poza
  • 336
  • 1
  • 16
  • Thanks! I tried something similar when I had a bunch of fit models from regressions that were giving me this error. I put them all into a list first, then fed that list as the first argument in the stargazer function and it solved the error. – Michael Ohlrogge Jul 27 '23 at 22:35
1

Not an answer, but maybe a hint: the following code

library(functional)
library(stargazer)

tabify <- function(models){

sgCurried = Curry(stargazer)

do.call(sgCurried, models)
}


mydf <- data.frame(Y = rnorm(15), Z = ceiling(rnorm(15)))

regr <- lm(Y ~ Z, data=mydf)

models = list(regr)

tabify(models)

... used to work with R 4.1.2, while it fails with R 4.2.2, (stargazer is 5.2.3 in both cases), producing the error reported by the OP.

Pietro Battiston
  • 7,930
  • 3
  • 42
  • 45