get_census_data
returns county-, tract-, and block-level Census data
for specified state(s). Using this function to download Census data in advance
can save considerable time when running predict_race
and census_helper
.
get_census_data(
key = Sys.getenv("CENSUS_API_KEY"),
states,
age = FALSE,
sex = FALSE,
year = "2020",
census.geo = c("tract", "block", "block_group", "county", "place", "zcta"),
retry = 3,
county.list = NULL
)
Output will be an object of class list
indexed by state.
Output will contain a subset of the following elements:
state
, age
, sex
,
county
, tract
, block_group
, block
, and place
.
A character string containing a valid Census API key, which can be requested from the U.S. Census API key signup page.
By default, attempts to find a census key stored in an
environment variable named CENSUS_API_KEY
.
which states to extract Census data for, e.g., c("NJ", "NY")
.
A TRUE
/FALSE
object indicating whether to condition on
age or not. If FALSE
(default), function will return Pr(Geolocation | Race).
If TRUE
, function will return Pr(Geolocation, Age | Race).
If sex
is also TRUE
, function will return Pr(Geolocation, Age, Sex | Race).
A TRUE
/FALSE
object indicating whether to condition on
sex or not. If FALSE
(default), function will return Pr(Geolocation | Race).
If TRUE
, function will return Pr(Geolocation, Sex | Race).
If age
is also TRUE
, function will return Pr(Geolocation, Age, Sex | Race).
A character object specifying the year of U.S. Census data to be downloaded.
Use "2010"
, or "2020"
. Default is "2020"
.
Warning: 2020 U.S. Census data is downloaded only when age
and
sex
are both FALSE
.
An optional character vector specifying what level of
geography to use to merge in U.S. Census 2010 geographic data. Currently
"county"
, "tract"
, "block"
, and "place"
are supported.
The number of retries at the census website if network interruption occurs.
A named list of character vectors of counties present in your voter.file, per state.
if (FALSE) get_census_data(states = c("NJ", "NY"), age = TRUE, sex = FALSE)
if (FALSE) get_census_data(states = "MN", age = FALSE, sex = FALSE, year = "2020")
Run the code above in your browser using DataLab