0

I am not sure why it seems so difficult to find information regarding summarizing non-quantitative variables with stargazer.

I would like a summary of the following time variable (number of observations, min and max value would be great)

Time<-c("2014-07-03 10:57:35 PDT", "2014-07-03 11:02:35 PDT", 
        "2014-07-03 11:07:35 PDT", "2014-07-03 11:12:35 PDT", 
        "2014-07-03 11:17:34 PDT", "2014-07-03 11:22:34 PDT")
Time<-as.POSIXlt(Time, format="%Y-%M-%d %H:%M:%S")

And a overall sample size and number of values of each category of the following factor.

Cat.Var<-rep(c("Level 1","Level 2"), each=3)

This seems so basic but there seems to be almost no documentation related to an issue like this. Maybe the Stargazer package is not what I should be using, but I would like these tables to visually match other output I have that was created with Stargazer.

Thank you!

Michael
  • 1,537
  • 6
  • 20
  • 42
  • What code are you using? What are the specific failures to "visually match other output"? – IRTFM Aug 24 '14 at 16:27
  • stargazer(data.frame(Cat.Var)) Treats that variable like a numeric one and displays a blank table. No "specific failures". I want to produce the latex table with stargazer and not some other package. – Michael Aug 24 '14 at 16:30
  • I don't see any examples in the vignette that suggest date-time or factor objects were going to be treated sensibly. The only examples are for ordinary numeric variables and regression models. Do you have any evidence that your goals were shared by the package author? – IRTFM Aug 24 '14 at 17:34
  • No I don't. Wasn't sure if I was missing something. I suppose it seems like the package is only for summarizing quantitative variables then. Thank you for looking into this! – Michael Aug 24 '14 at 17:44
  • 1
    No, it's not really designed for summarizing. It's designed for displaying regression model results. – IRTFM Aug 24 '14 at 17:52
  • Thanks @BondedDust & @Michael. Still useful information to have on Stack, finding this answer saved me wasting more time! I resorted to using `tableNominal()` from the `library(reporttools)`. – Luke Singham Oct 08 '14 at 00:07

1 Answers1

0

Stargazer is capable of producing a well formatted summary table of factor variable. Just feed the factor variables into the ftable function from base r, and then feed that into stargazer.

For example:

stargazer(ftable(data.set$gender, data.set$year), type="text")

This summarizes the gender distribution of your data for each year. Stargazer requires ftable to have at least two factor variables, otherwise it produces an error, but this is very easy to get around if you just create a factor variable of 1's for every observation.

Johan
  • 199
  • 1
  • 4