I am unsure whether to post this here or the tidycensus package.
I am doing a ZIP level analysis in a business context and we are interested in getting ZCTA level demographic data from Census because it is the best approximation for ZIP codes. A problem we are running into is that none of the ZCTA data has a state associated with it. E.g.
library(tidycensus)
library(mapview)
zcta_income <- get_acs(
geography = "zcta",
variables = "B19013_001",
year = 2021,
geometry = TRUE
)
# No State info
head(zcta_income)
# Creates a map of the entire US, whereas I'd like to just be of a single state or county
mapview(zcta_income, zcol = "estimate")
When I google this I see comments like "Well, this is because Census does not return State data". But when I created the choroplethrZip package I had this exact same problem and was able to solve it. I stored it in an object called zip.regions. E.g.
library(choroplethrZip)
data(zip.regions)
head(zip.regions)
region state.name county.name county.fips.numeric cbsa cbsa.title
1 70560 louisiana iberia 22045 10020 <NA>
2 70510 louisiana vermilion 22113 10020 <NA>
3 70592 louisiana lafayette 22055 10020 <NA>
4 70548 louisiana vermilion 22113 10020 <NA>
5 70560 louisiana vermilion 22113 10020 <NA>
6 70578 louisiana lafayette 22055 10020 <NA>
metropolitan.micropolitan.statistical.area
1 <NA>
2 <NA>
3 <NA>
4 <NA>
5 <NA>
6 <NA>
To see where I got the data from, type ?zip.regions:
Data comes from the US Census Bureau's 2010 ZCTA to County Relationship File (https://www.census.gov/geo/maps-data/data/zcta_rel_download.html), 2010 ZCTA to Metropolitan and Micropolitan Statistical Areas Relationship File and the Core Based Statistical Areas (CBSAs) and Combined Statistical Areas (CSAs) Metropolitan and Micropolitan Delineation files (http://www.census.gov/population/metro/data/def.html).
Note that this data is from 2010 and the first link no longer works. But if I Google "ZCTA Relationship File" you wind up here and if you click through to the "2020 ZCTA to County Relationship File" you wind up here. It appears that perhaps they only update this file in years ending in 0. If you search that file for "ZCTA5 + < your zip code >" You'll probably find both the state and county for your ZCTA. For example, here is row for "ZCTA5 90210":
221704258470394|90210|ZCTA5 90210|27823432|153478|G6350|B5|S|275901063468976|06037|Los Angeles County|10513491099|1787501506|G4020|H1|A|27823432|153478
The key point is not just the text "Los Angeles County". It is also the entry before that (06037): 06 is the FIPS code for California and 037 is the FIPS code for Los Angeles County. So this file will let you filter a national dataset to "All ZCTAs in a state" as well as "All ZCTAs in a county."
I am not sure if you were aware of this file or not. But I think it would help a lot of people if this data wound up in either tigris or tidycensus, since so many demographic questions in business / marketing try to use ZCTAs.
@walkerke Is this data / functionality that you are interested in adding to the package?
I am unsure whether to post this here or the tidycensus package.
I am doing a ZIP level analysis in a business context and we are interested in getting ZCTA level demographic data from Census because it is the best approximation for ZIP codes. A problem we are running into is that none of the ZCTA data has a state associated with it. E.g.
When I google this I see comments like "Well, this is because Census does not return State data". But when I created the choroplethrZip package I had this exact same problem and was able to solve it. I stored it in an object called
zip.regions. E.g.To see where I got the data from, type
?zip.regions:Note that this data is from 2010 and the first link no longer works. But if I Google "ZCTA Relationship File" you wind up here and if you click through to the "2020 ZCTA to County Relationship File" you wind up here. It appears that perhaps they only update this file in years ending in 0. If you search that file for "ZCTA5 + < your zip code >" You'll probably find both the state and county for your ZCTA. For example, here is row for "ZCTA5 90210":
The key point is not just the text "Los Angeles County". It is also the entry before that (06037): 06 is the FIPS code for California and 037 is the FIPS code for Los Angeles County. So this file will let you filter a national dataset to "All ZCTAs in a state" as well as "All ZCTAs in a county."
I am not sure if you were aware of this file or not. But I think it would help a lot of people if this data wound up in either tigris or tidycensus, since so many demographic questions in business / marketing try to use ZCTAs.
@walkerke Is this data / functionality that you are interested in adding to the package?