-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
get_decennial returning error on tract geography #129
Comments
This is because the Census API requires a state/county combination to retrieve tracts from the Decennial Census. This issue is similar to #121 (comment) where a state and county is required to get county subdivision data. I wrote up some of this in a blog post with plenty of examples. Below is some code that should get what you're looking for. library(tidyverse)
library(tidycensus)
vars10 <- c("P005003", "P005004", "P005006", "P004003")
il_counties <- fips_codes %>%
filter(state %in% "IL")
il <- map_dfr(
il_counties$county_code,
~ get_decennial(
geography = "tract",
state = "IL",
county = .x,
variables = vars10,
year = 2010,
summary_var = "P001001",
geometry = FALSE
)
)
head(il)
#> # A tibble: 6 x 5
#> GEOID NAME variable value summary_value
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 170010001… Census Tract 1, Adams County, Il… P005003 4370 4627
#> 2 170010002… Census Tract 2.01, Adams County,… P005003 1868 1986
#> 3 170010002… Census Tract 2.02, Adams County,… P005003 2648 2999
#> 4 170010004… Census Tract 4, Adams County, Il… P005003 3493 4322
#> 5 170010005… Census Tract 5, Adams County, Il… P005003 1866 2337
#> 6 170010006… Census Tract 6, Adams County, Il… P005003 3430 3718 Created on 2018-11-06 by the reprex package (v0.2.1) @walkerke Would it be worth building this logic into |
Thanks @mfherman for the detailed response. Yes, I think it is worth building this logic into tidycensus. With the move to the new Census API endpoints, Census removed this functionality; tracts used to be available by state for the decennial Census. This was an issue for the new ACS endpoints as well, but Census fixed it; @loganpowell do you think the API team would be amenable to this request as well? |
I'm quite a novice package developer, but I can try to make a start on adding this to tidycensus. Even if they do fix the Census API, it may still be useful for other geographies like county subdivisions and block groups. |
Thanks @mfherman ! |
Hello,
Running the code from the example works perfectly, but when I switch "county" to tract, it returns an error
Not sure what's causing this, but it's recurring across at least several P tables.
The text was updated successfully, but these errors were encountered: