ACS/Census API中的未知变量

huangapple go评论68阅读模式
英文:

Unknown variable in ACS/Census API

问题

我正在尝试使用R获取各个邮政编码地区的居住状况普查数据。我使用了我用于所有其他API调用的语法,并且确切地从API密钥中复制了变量名称,网址在这里:https://api.census.gov/data/2021/acs/acs1/groups/C25032.html

这些变量在此调用中也完全相同:

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

这是我的尝试:

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

这返回以下错误:
错误:您的API调用存在错误。API返回的消息是错误:未知变量 'C25032001E'。

我期望这会创建一个包含每个邮政编码(GEOID)以及它们在该邮政编码中的总单位估算的数据框架。添加下划线或删除 'E' 也不会改变任何内容。

我原本计划将此代码用于租户和自有住房单位,但它们也不起作用。我需要使用邮政编码地理信息来收集数据。

英文:

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.

答案1

得分: 1

在tidycensus中,变量的“E”或“M”后缀是不必要的,根据 tidycensus基本使用说明

此外,在2021年ACS 1年数据集中,不支持地理位置“zcta”。相反,可以使用geography = "puma"来提取C25032_001变量。

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

# 返回错误,因为“zcta”不是公开使用微数据样本中支持的地理位置
acs_total_units <- get_acs(geography = "zcta",
                           state = "GA",
                           survey = "acs1",
                           variables = "C25032_001", year = 2021)

...和输出:

> 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 hierarchy.
>

然而,当我们将geography = "puma"时,相同的查询返回所请求的数据。

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

head(acs_total_units)

在2021年ACS 1年调查中,乔治亚州有72个PUMA地区。我们将打印前六个。

> head(acs_total_units)
# A tibble: 6 × 5
  GEOID   NAME                                                                        variable¹ estimate²   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
>

完整的2021年ACS-1公开使用微数据样本可用地理位置列表可在U.S. Census API Site找到,但支持的地理位置表在此处作为参考。

英文:

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 = &quot;puma&quot;.

library(tidyverse)
library(tidycensus)
variables &lt;- load_variables(2021, &quot;acs1&quot;, cache = TRUE)

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

...and the output:

&gt; acs_total_units &lt;- get_acs(geography = &quot;zcta&quot;,
+                            state = &quot;GA&quot;,
+                            survey = &quot;acs1&quot;,
+                            variables = &quot;C25032_001&quot;, 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 &#39;13&#39; for state &#39;GA&#39;
Error: Your API call has errors.  The API message returned is error: unknown/unsupported geography heirarchy.
&gt;

However, when we set geography = &quot;puma&quot; the same query returns the requested data.

acs_total_units &lt;- get_acs(geography = &quot;puma&quot;,
                           state = &quot;GA&quot;,
                           survey = &quot;acs1&quot;,
                           variables = &quot;C25032_001&quot;, 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.

&gt; head(acs_total_units)
# A tibble: 6 &#215; 5
  GEOID   NAME                                                                        varia…&#185; estim…&#178;   moe
  &lt;chr&gt;   &lt;chr&gt;                                                                       &lt;chr&gt;     &lt;dbl&gt; &lt;dbl&gt;
1 1300100 Coastal Regional Commission (South)--Glynn Camden &amp; McIntosh Counties PUMA… C25032…   61393  2124
2 1300200 Coastal Regional Commission (West)--Liberty, Bryan &amp; Long Counties PUMA; G… C25032…   45555  2022
3 1300300 Coastal Regional Commission (North)--Bulloch, Effingham &amp; 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 &amp; Outside Savanna… C25032…   50993  4055
6 1300500 Southern Georgia Regional Commission (East &amp; Central) PUMA, Georgia         C25032…   58713  2413
# … with abbreviated variable names &#185;​variable, &#178;​estimate
&gt; 

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.

ACS/Census API中的未知变量

huangapple
  • 本文由 发表于 2023年2月27日 02:55:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574308.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定