Summarizing Factors and Times with Stargazer
Asked Answered
I

1

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!

Ira answered 24/8, 2014 at 16:15 Comment(6)
What code are you using? What are the specific failures to "visually match other output"?Cess
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.Ira
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?Cess
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!Ira
No, it's not really designed for summarizing. It's designed for displaying regression model results.Cess
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).Unwrap
F
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.

Fantastically answered 7/4, 2016 at 2:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.