nagrom11
nagrom11

Reputation: 11

Unknown variable in ACS/Census API

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.

Upvotes: 1

Views: 691

Answers (1)

Len Greski
Len Greski

Reputation: 10865

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

Upvotes: 1

Related Questions