0

I am trying to get census data for tenure status in various zip codes using R. I used the syntax that I used for all of my other API calls and copied the variable name exactly from the API key here: https://api.census.gov/data/2021/acs/acs1/groups/C25032.html

The variables also appear identically in this call:

variables <- load_variables(2021, "acs1", cache = TRUE)

Here is what I tried:

acs_total_units <- get_acs(geography = "zcta", 
                  variables = "C25032001E", year = 2021)

This returns the following error: Error: Your API call has errors. The API message returned is error: error: unknown variable 'C25032001E'.

I expected this to create a dataframe with every zip code (GEOID) and their estimates for the total units in that zip code. Adding an underscore or removing the E does not change anything.

I was going to copy this code for renters and owner-occupied units, but those do not work either. I need to use the zip code geography for the data I am gathering.

Len Greski
  • 10,505
  • 2
  • 22
  • 33
nagrom11
  • 1
  • 1
  • `C25032001E` doesn't exist as a variable (at least not in the `acs1` dataset). You need to have a look into the list of variable names you're pulling into `variables` and decide which one you'd like to extract. – arg0naut91 Feb 26 '23 at 19:16

1 Answers1

1

In tidycensus, the "E" or "M" suffixes for variables are not required, per the tidycensus basic usage instructions.

Also, in the 2021 ACS 1 year data set, the geography zcta is not supported. Instead, one can extract the C25032_001 variable with geography = "puma".

library(tidyverse)
library(tidycensus)
variables <- load_variables(2021, "acs1", cache = TRUE)

# returns error because zcta is not a supported geography in the public use microdata sample
acs_total_units <- get_acs(geography = "zcta",
                           state = "GA",
                           survey = "acs1",
                           variables = "C25032_001", year = 2021)

...and the output:

> acs_total_units <- get_acs(geography = "zcta",
+                            state = "GA",
+                            survey = "acs1",
+                            variables = "C25032_001", year = 2021)
Getting data from the 2021 1-year ACS
The 1-year ACS provides data for geographies with populations of 65,000 and greater.
Using FIPS code '13' for state 'GA'
Error: Your API call has errors.  The API message returned is error: unknown/unsupported geography heirarchy.
>

However, when we set geography = "puma" the same query returns the requested data.

acs_total_units <- get_acs(geography = "puma",
                           state = "GA",
                           survey = "acs1",
                           variables = "C25032_001", year = 2021)

head(acs_total_units)

In the 2021 ACS 1 year survey, the state of Georgia has 72 PUMA areas. We'll print the first six.

> head(acs_total_units)
# A tibble: 6 × 5
  GEOID   NAME                                                                        varia…¹ estim…²   moe
  <chr>   <chr>                                                                       <chr>     <dbl> <dbl>
1 1300100 Coastal Regional Commission (South)--Glynn Camden & McIntosh Counties PUMA… C25032…   61393  2124
2 1300200 Coastal Regional Commission (West)--Liberty, Bryan & Long Counties PUMA; G… C25032…   45555  2022
3 1300300 Coastal Regional Commission (North)--Bulloch, Effingham & Screven Counties… C25032…   58124  2590
4 1300401 Coastal Regional Commission (East)--Chatham County (West Central)--Savanna… C25032…   70035  4145
5 1300402 Coastal Regional Commission (East)--Chatham County (East & Outside Savanna… C25032…   50993  4055
6 1300500 Southern Georgia Regional Commission (East & Central) PUMA, Georgia         C25032…   58713  2413
# … with abbreviated variable names ¹​variable, ²​estimate
> 

The complete list of geographies available for the 2021 ACS-1 public use microdata sample is available on the U.S. Census API Site, but the supported geographies table is posted here as a reference.

enter image description here

Len Greski
  • 10,505
  • 2
  • 22
  • 33
  • Thanks for the help! I will see if I can mangle something together with PUMAs, but they are much less granular as, if I recall correctly, they round up groups of 100,000 people and I am working with cities as small as 2,000. I am surprised to hear the ACS 1yr 2021 survey does not support zcta. All of my other calls worked. Do you know why this is? For example: acs_pop_data <- get_acs(geography = "zcta", variables = "B01003_001", year = 2021) Works as expected. – nagrom11 Feb 27 '23 at 14:10
  • @nagrom11 - the query in your comment extracts from the ACS5 survey, not the ACS1 survey, per the messages returned by tidycensus API: `> acs_pop_data <- get_acs(geography = "zcta", variables = "B01003_001", year = 2021) ` **Getting data from the 2017-2021 5-year ACS** – Len Greski Feb 28 '23 at 02:19
  • 1
    @nagrom11 the 1-year ACS only includes data on geographies with population 65,000 and greater, which excludes ZCTAs which have smaller populations than that. I'd recommend the first two chapters of my book for an overview / tips on formatting data requests with tidycensus: https://walker-data.com/census-r/index.html – kwalkertcu Mar 02 '23 at 14:27