-
-
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
county subdivision not supported? #121
Comments
You'll need to specify a state: get_acs(geography = "county subdivision",
variables = c(medianIncome = "B19013_001"),
state = "TX")
Getting data from the 2012-2016 5-year ACS
Using FIPS code '48' for state 'TX'
# A tibble: 862 x 5
GEOID NAME variable estimate moe
<chr> <chr> <chr> <dbl> <dbl>
1 4800190650 Cayuga CCD, Anderson County, Texas medianInco… 53750 21623
2 4800191205 Elkhart CCD, Anderson County, Texas medianInco… 42194 4979
3 4800191390 Frankston CCD, Anderson County, Texas medianInco… 52099 4865
4 4800192615 Montalba-Tennessee Colony CCD, Anderson Coun… medianInco… 51875 9801
5 4800192945 Palestine CCD, Anderson County, Texas medianInco… 38556 3938
6 4800390085 Andrews North CCD, Andrews County, Texas medianInco… 71154 7246
7 4800390090 Andrews South CCD, Andrews County, Texas medianInco… 57419 24519
8 4800591045 Diboll CCD, Angelina County, Texas medianInco… 45304 4623
9 4800591855 Huntington CCD, Angelina County, Texas medianInco… 48769 7545
10 4800592325 Lufkin CCD, Angelina County, Texas medianInco… 41895 1986
# ... with 852 more rows |
Can we have more than one state? The code below fails.
get_acs(geography = "county subdivision",
variables = c(medianIncome = "B19013_001"),
state = c("NH", "ME", "VT", "NY"))
Daniel Lee
Professor of Economics, Data Analyst, Tourism Economist
http://daniellee.netlify.com/
https://www.linkedin.com/in/daniel-lee-data-analyst
On Thursday, October 4, 2018, 7:39:47 PM EDT, Kyle Walker <notifications@github.com> wrote:
You'll need to specify a state:
get_acs(geography = "county subdivision",
variables = c(medianIncome = "B19013_001"),
state = "TX")
Getting data from the 2012-2016 5-year ACS
Using FIPS code '48' for state 'TX'
# A tibble: 862 x 5
GEOID NAME variable estimate moe
<chr> <chr> <chr> <dbl> <dbl>
1 4800190650 Cayuga CCD, Anderson County, Texas medianInco… 53750 21623
2 4800191205 Elkhart CCD, Anderson County, Texas medianInco… 42194 4979
3 4800191390 Frankston CCD, Anderson County, Texas medianInco… 52099 4865
4 4800192615 Montalba-Tennessee Colony CCD, Anderson Coun… medianInco… 51875 9801
5 4800192945 Palestine CCD, Anderson County, Texas medianInco… 38556 3938
6 4800390085 Andrews North CCD, Andrews County, Texas medianInco… 71154 7246
7 4800390090 Andrews South CCD, Andrews County, Texas medianInco… 57419 24519
8 4800591045 Diboll CCD, Angelina County, Texas medianInco… 45304 4623
9 4800591855 Huntington CCD, Angelina County, Texas medianInco… 48769 7545
10 4800592325 Lufkin CCD, Angelina County, Texas medianInco… 41895 1986
# ... with 852 more rows
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I like to make use of the library(tidyverse)
library(tidycensus)
my_states <- c("NH", "ME", "VT", "NY")
map_dfr(my_states, ~ get_acs(geography = "county subdivision",
variables = c(medianIncome = "B19013_001"),
state = .)
)
#> Getting data from the 2012-2016 5-year ACS
#> Getting data from the 2012-2016 5-year ACS
#> Getting data from the 2012-2016 5-year ACS
#> Getting data from the 2012-2016 5-year ACS
#> # A tibble: 2,071 x 5
#> GEOID NAME variable estimate moe
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 33001010… Alton town, Belknap County, New Ha… medianInc… 76676 11670
#> 2 33001032… Barnstead town, Belknap County, Ne… medianInc… 70037 6457
#> 3 33001047… Belmont town, Belknap County, New … medianInc… 60938 7012
#> 4 33001106… Center Harbor town, Belknap County… medianInc… 70625 20060
#> 5 33001287… Gilford town, Belknap County, New … medianInc… 63125 10372
#> 6 33001289… Gilmanton town, Belknap County, Ne… medianInc… 68085 6917
#> 7 33001401… Laconia city, Belknap County, New … medianInc… 48893 4719
#> 8 33001471… Meredith town, Belknap County, New… medianInc… 63846 8902
#> 9 33001515… New Hampton town, Belknap County, … medianInc… 74293 8257
#> 10 33001673… Sanbornton town, Belknap County, N… medianInc… 72721 7287
#> # … with 2,061 more rows Created on 2018-10-04 by the reprex package (v0.2.1) |
Fantastic! Thank you so much.
I tried the same code for get_decennial() and didn't work. It turns out:
- get_acs() requires only state specified, while
- get_decennial() requires both state and county specified.
How would you modified your code for get_decennial()?
Thank you so much in advance.
Daniel Lee
Professor of Economics, Data Analyst, Tourism Economist
http://daniellee.netlify.com/
https://www.linkedin.com/in/daniel-lee-data-analyst
On Thursday, October 4, 2018, 9:06:36 PM EDT, Matt Herman <notifications@github.com> wrote:
I like to make use of the map family of functions from the purrr package for a task like this. Using the formula syntax with map_dfr() makes it very concise.
library(tidyverse)
library(tidycensus)
my_states <- c("NH", "ME", "VT", "NY")
map_dfr(my_states, ~ get_acs(geography = "county subdivision",
variables = c(medianIncome = "B19013_001"),
state = .)
)
#> Getting data from the 2012-2016 5-year ACS
#> Getting data from the 2012-2016 5-year ACS
#> Getting data from the 2012-2016 5-year ACS
#> Getting data from the 2012-2016 5-year ACS
#> # A tibble: 2,071 x 5
#> GEOID NAME variable estimate moe
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 33001010… Alton town, Belknap County, New Ha… medianInc… 76676 11670
#> 2 33001032… Barnstead town, Belknap County, Ne… medianInc… 70037 6457
#> 3 33001047… Belmont town, Belknap County, New … medianInc… 60938 7012
#> 4 33001106… Center Harbor town, Belknap County… medianInc… 70625 20060
#> 5 33001287… Gilford town, Belknap County, New … medianInc… 63125 10372
#> 6 33001289… Gilmanton town, Belknap County, Ne… medianInc… 68085 6917
#> 7 33001401… Laconia city, Belknap County, New … medianInc… 48893 4719
#> 8 33001471… Meredith town, Belknap County, New… medianInc… 63846 8902
#> 9 33001515… New Hampton town, Belknap County, … medianInc… 74293 8257
#> 10 33001673… Sanbornton town, Belknap County, N… medianInc… 72721 7287
#> # … with 2,061 more rows
Created on 2018-10-04 by the reprex package (v0.2.1)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
It appears that the Census API doesn't allow you to call all county subdivision in a given state for the Decennial Census files, while you can for the ACS subject/detail tables. So one approach I came up with is to use the library(tidyverse)
library(tidycensus)
my_states <- c("NH", "ME", "VT", "NY")
my_counties <- fips_codes %>%
filter(state %in% my_states)
vars10 <- c(seasonalHome = "H005006", # vacant for seasonal, recreational, or occasional use
totalHome = "H001001", # total number of homoes in 2010
pop2010 = "P001001") # total population in 2010
map2_dfr(
my_counties$state_code, my_counties$county_code,
~ get_decennial(
geography = "county subdivision",
state = .x,
county = .y,
variables = vars10,
year = 2010,
geometry = FALSE
)
)
#> # A tibble: 6,213 x 4
#> GEOID NAME variable value
#> <chr> <chr> <chr> <dbl>
#> 1 2300138565 Leeds town, Androscoggin County, Maine seasonalHo… 91
#> 2 2300102060 Auburn city, Androscoggin County, Maine seasonalHo… 170
#> 3 2300119105 Durham town, Androscoggin County, Maine seasonalHo… 9
#> 4 2300129255 Greene town, Androscoggin County, Maine seasonalHo… 142
#> 5 2300138740 Lewiston city, Androscoggin County, Maine seasonalHo… 96
#> 6 2300140035 Lisbon town, Androscoggin County, Maine seasonalHo… 20
#> 7 2300140665 Livermore town, Androscoggin County, Maine seasonalHo… 168
#> 8 2300140770 Livermore Falls town, Androscoggin County… seasonalHo… 24
#> 9 2300144585 Mechanic Falls town, Androscoggin County,… seasonalHo… 9
#> 10 2300146160 Minot town, Androscoggin County, Maine seasonalHo… 6
#> # … with 6,203 more rows Created on 2018-10-05 by the reprex package (v0.2.1) |
Thank you so much, Matt. This is fantastic!
Daniel Lee
Professor of Economics, Data Analyst, Tourism Economist
http://daniellee.netlify.com/
https://www.linkedin.com/in/daniel-lee-data-analyst
On Friday, October 5, 2018, 7:45:00 PM EDT, Matt Herman <notifications@github.com> wrote:
It appears that the Census API doesn't allow you to call all county subdivision in a given state for the Decennial Census files, while you can for the ACS subject/detail tables. So one approach I came up with is to use the fips_codes dataset which is included in tidycensus to select all the counties within your requested states. Then you an loop over each of the state/county FIPS code combinations and request the county subdivisions in each of the counties. It hits the Census API for each county (102 in this case) but I'm not sure of a different solution at the moment.
library(tidyverse)
library(tidycensus)
my_states <- c("NH", "ME", "VT", "NY")
my_counties <- fips_codes %>%
filter(state %in% my_states)
vars10 <- c(seasonalHome = "H005006", # vacant for seasonal, recreational, or occasional use
totalHome = "H001001", # total number of homoes in 2010
pop2010 = "P001001") # total population in 2010
map2_dfr(
my_counties$state_code, my_counties$county_code,
~ get_decennial(
geography = "county subdivision",
state = .x,
county = .y,
variables = vars10,
year = 2010,
geometry = FALSE
)
)
#> # A tibble: 6,213 x 4
#> GEOID NAME variable value
#> <chr> <chr> <chr> <dbl>
#> 1 2300138565 Leeds town, Androscoggin County, Maine seasonalHo… 91
#> 2 2300102060 Auburn city, Androscoggin County, Maine seasonalHo… 170
#> 3 2300119105 Durham town, Androscoggin County, Maine seasonalHo… 9
#> 4 2300129255 Greene town, Androscoggin County, Maine seasonalHo… 142
#> 5 2300138740 Lewiston city, Androscoggin County, Maine seasonalHo… 96
#> 6 2300140035 Lisbon town, Androscoggin County, Maine seasonalHo… 20
#> 7 2300140665 Livermore town, Androscoggin County, Maine seasonalHo… 168
#> 8 2300140770 Livermore Falls town, Androscoggin County… seasonalHo… 24
#> 9 2300144585 Mechanic Falls town, Androscoggin County,… seasonalHo… 9
#> 10 2300146160 Minot town, Androscoggin County, Maine seasonalHo… 6
#> # … with 6,203 more rows
Created on 2018-10-05 by the reprex package (v0.2.1)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
FYI -- I just wrote up some of this in a little more detail on my blog: |
Matt,
This is wonderful. Thank you again for sharing.
Daniel Lee
Professor of Economics, Data Analyst, Tourism Economist
http://daniellee.netlify.com/
https://www.linkedin.com/in/daniel-lee-data-analyst
On Sunday, October 7, 2018, 1:34:15 PM EDT, Matt Herman <notifications@github.com> wrote:
FYI -- I just wrote up some of this in a little more detail on my blog:
https://mattherman.info/blog/tidycensus-mult/
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Based on walkerke#121 (comment) this seems to be required.
Is "County Subdivision" not supported any more? The code below returns the following error message. Thank you.
Error: Your API call has errors. The API message returned is error: unknown/unsupported geography heirarchy.
get_acs(geography = "county subdivision",
variables = c(medianIncome = "B19013_001"),
year = 2016,
geometry = FALSE)
The text was updated successfully, but these errors were encountered: