Browsed by
Tag: Stata

Stata to R: How to Tabulate a Categorical Variable

Stata to R: How to Tabulate a Categorical Variable

When working with a data set, one of the first things I do is look at the count and relative frequency of categorical variables of interest. In Stata, this is relatively straight forward with the tab command. In R, however, it isn’t quite as straight forward, but still possible. The equivalent code in R, is: dataset %>% group_by(var) %>% summarise(n = n()) %>% mutate(totalN = (cumsum(n)), percent = round((n / sum(n)), 3), cumpercent = round(cumsum(freq = n / sum(n)), 3))…

Read More Read More