hrecht / censusapi

R package to retrieve U.S. Census data and metadata via API
https://www.hrecht.com/censusapi/
169 stars 31 forks source link

SAHIE data with getCensus() not generating all age/sex/race groups #34

Closed aniruhil closed 6 years ago

aniruhil commented 6 years ago

sahie16 <- getCensus(name = "timeseries/healthins/sahie", vars = c("NAME", "AGE_DESC", "RACE_DESC", "SEX_DESC", "IPRCAT", "IPR_DESC", "PCTUI_PT", "PCTUI_LB90", "PCTUI_UB90", "PCTUI_MOE"), region = "county:*", regionin = "state:39", time = 2016)

This does not generate all RACE or AGE or SEX categories.

Instead, I get

table(sahie16$AGE_DESC) Under 65 years 528

table(sahie16$RACE_DESC) All Races 528

table(sahie16$SEX_DESC) Both Sexes 528

What am I doing wrong in asking for specific variables but all categories?

aniruhil commented 6 years ago

I figured it out: you have to specify AGECAT, RACECAT, SEXCAT with AGE_DESC, RACE_DESC, SEX_DESC in order for each group to be pulled. Just specifying the *_DESC variables defaults to whatever group is assigned a category value of 0.

Not sure why this would be preferred behavior over allowing one to specify just the more informative *_DESC variables (since they have labels).

hrecht commented 6 years ago

Glad you were able to figure it out! My understanding is that the CAT variables are the required category selectors and DESC only describes the category variables that were pulled. I believe you can use CAT without DESC to get a specific type, but not the reverse.