Skip to content

Commit

Permalink
Merge pull request #31 from mrembert/master
Browse files Browse the repository at this point in the history
Adding the ability to pull data for Workforce Investment Areas
  • Loading branch information
medewitt committed Apr 28, 2024
2 parents e0aeeba + 7304482 commit b1e9ac3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
12 changes: 12 additions & 0 deletions R/geo_codes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Geographic Codes
#'
#' @format a dataframe with 5423 rows and 3 columns:
#' \describe{
#' \item{geography}{geography}
#' \item{label}{label}
#' \item{geolevel}{geolevel}
#' ...
#' }
#' @source \url{https://lehd.ces.census.gov/data/schema/latest/label_geography.csv}

"geo_codes"
27 changes: 19 additions & 8 deletions R/get_qwi.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,23 @@ get_qwi <- function(years,
A02 = "&ownercode=A02")
}

if(!geography %in% c("cbsa", "county")){
if(!geography %in% c("cbsa", "county", "wia")){
stop("Please enter a county or cbsa in the `geography` field")
}

if(geography == "cbsa"){
geography <- "metropolitan+statistical+area/micropolitan+statistical+area"
} else{
}
if(geography == "wia"){
geography <- "workforce+investment+area"
wia_codes <- geo_codes %>%
filter(geo_level == "W") %>%
mutate(state_fips = substr(geography, start = 1, stop = 2),
geography = substr(geography, start = 3, stop = nchar(geography))
) %>%
filter(state_fips %in% states) %>%
pull(geography)
}else{
geography <- geography
}

Expand All @@ -229,15 +239,16 @@ get_qwi <- function(years,
industries,
states) %>%
dplyr::mutate(url = paste(
"https://api.census.gov/data/timeseries/qwi/",endpoint_to_retrieve,"?get=",
"https://api.census.gov/data/timeseries/qwi/", endpoint_to_retrieve, "?get=",
variables,
"&for=",geography,":*&in=state:",
states,
"&year=",year_collapsed,
"&quarter=",quarter_collapsed,
"&for=", geography, ifelse(geography == "county" | geography == "state", ":*", ""),
ifelse(geography == "workforce+investment+area", paste0(":",paste0(wia_codes, collapse=",")),""),
"&in=state:", states,
"&year=", year_collapsed,
"&quarter=", quarter_collapsed,
cross_tab,
owner_code,
"&seasonadj=",seasonadj,
"&seasonadj=", seasonadj,
"&industry=",
industries,
"&key=",
Expand Down
Binary file added data/geo_codes.rda
Binary file not shown.

0 comments on commit b1e9ac3

Please sign in to comment.