Robert Tan
Robert Tan

Reputation: 674

How/where to match tidycensus variables with census bureau variables?

Problem

I am given a long list of specific variable codes for the DP05 table - in the census bureau format. For instance:

target_dp05_vars = c(perc_white = "HC03_VC53",
    perc_black = "HC03_VC55",
    perc_native = "HC03_VC56")

Since tidycensus uses its own variable naming convention, I can't use the above easily. How do I easily crosswalk to the tidycensus definition?

Temporary solution

In the meantime, I've downloaded the bureau file manually and eliminated rows with HC02 and HC04 prefixes to match with tidycensus to create an internal crosswalk (because it's at least positionally correct) but it's tedious.

I'd love to just feed those HCs as a named vector into get_acs() and perhaps just specify the table as DP05.

Upvotes: 1

Views: 2344

Answers (1)

kwalkertcu
kwalkertcu

Reputation: 1061

tidycensus doesn't use its own variable naming convention - it uses variable IDs as specified by the Census API. For example, see https://api.census.gov/data/2017/acs/acs5/profile/variables.html, which is accessible in R with:

library(tidycensus)
dp17 <- load_variables(2017, "acs5/profile", cache = TRUE)

The IDs you've provided appear to be FactFinder codes.

If you want the full DP05 table in one tidycensus call, you can do the following (e.g. for counties in New York) with tidycensus 0.9:

dp05 <- get_acs(geography = "county", 
                table = "DP05", 
                state = "NY")

Mapping of variable IDs to their meanings are in turn available with load_variables().

Note: I am getting intermittent server errors with these calls from the API, which may be due to the government shutdown. If it doesn't work at first, try again.

Upvotes: 3

Related Questions