Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow requesting subsets of ZCTAs #287

Closed
kmishra9 opened this issue Aug 28, 2020 · 5 comments
Closed

Allow requesting subsets of ZCTAs #287

kmishra9 opened this issue Aug 28, 2020 · 5 comments

Comments

@kmishra9
Copy link

kmishra9 commented Aug 28, 2020

Hey there,

One use case I'm using tidycensus for is to generate ~100 covariates for a model for data that gets refreshed decently often. For that reason, I'd like to avoid pulling all 100 covariates (which, as I'm sure you can imagine, can take a long time) for every zip code in the country, and instead would love to specify the necessary zip codes before the query, similar to how the state parameter is used when working at the state level.

library('tidycensus')
library('tidyverse')

monthly_housing_costs <- c(
    "MonthlyHousingCost_0_100"     = "B25104_002",
    "MonthlyHousingCost_100_199"   = "B25104_003",
    "MonthlyHousingCost_200_299"   = "B25104_004",
    "MonthlyHousingCost_300_399"   = "B25104_005",
    "MonthlyHousingCost_400_499"   = "B25104_006",
    "MonthlyHousingCost_500_599"   = "B25104_007",
    "MonthlyHousingCost_600_699"   = "B25104_008",
    "MonthlyHousingCost_700_799"   = "B25104_009",
    "MonthlyHousingCost_800_899"   = "B25104_010",
    "MonthlyHousingCost_900_999"   = "B25104_011",
    "MonthlyHousingCost_1000_1499" = "B25104_012",
    "MonthlyHousingCost_1500_1999" = "B25104_013",
    "MonthlyHousingCost_2000_2499" = "B25104_014",
    "MonthlyHousingCost_2500_2999" = "B25104_015",
    "MonthlyHousingCost_3000_plus" = "B25104_016",
    "MonthlyHousingCost_0"         = "B25104_017"
)

acs_2017_housing_costs_zcta_limited <- get_acs(
    geography = "zcta",
    variables = monthly_housing_costs,
    year = 2017,
    output = "wide",
    state = c('92867', '94608')
) %>% glimpse()
#> Getting data from the 2013-2017 5-year ACS
#> Error: ZCTAs can only be requested for the entire country, not within states or counties.

Created on 2020-08-28 by the reprex package (v0.3.0)

@mfherman
Copy link
Collaborator

This could be implemented as the API accepts one or more ZCTAs as a parameter:

https://api.census.gov/data/2018/acs/acs5?get=B01003_001E&for=zip%20code%20tabulation%20area:11222,11211,10536

@walkerke, what do you think? I know you've shied away from adding too many arguments to get_acs() - just not sure how common it would be for a user to want a subset of ZCTAs.

@walkerke
Copy link
Owner

Good find @mfherman! I think this makes sense as a feature given that the API accommodates it. It wouldn't help for calls with geometry = TRUE as we still have to pull in the full ZCTA geometry then subset given how Census makes the data available, but for non-geometry calls it'd be nice to have.

@kmishra9
Copy link
Author

kmishra9 commented Sep 19, 2020

Great! I'm glad its possible, in scope, and look forward to the day we can specify ZCTAs :)

Until then, I'll continue caching results locally (2 seconds vs 20 minutes)!

@walkerke
Copy link
Owner

I could see this as part of a broader discussion tied to #298, where users could specify geographical hierarchies that are not tied to the traditional state/county hierarchy that we tend to accommodate in the package. I'm sending up a new version to CRAN today but I'd like to keep this in mind for the next release.

@walkerke
Copy link
Owner

This is now implemented thanks to @mfherman!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants