::opts_chunk$set(echo = TRUE) knitr
Use of BLS API
Setup
Use the BLS API to retrieve the data
# Set the library and install the packages
library(devtools)
library(blsR)
# The introduction about this package: https://cran.r-project.org/web/packages/blsR/blsR.pdf
::install_github("groditi/blsR")
devtools
# Acquire the API by registering through https://www.bls.gov/developers/home.htm
bls_set_key("your personal API")
<- get_series(series_id = "series id you found",
test_series start_year = 2016,
end_year = 2024,
api_key = bls_get_key())
I work through the series number by https://data.bls.gov/PDQWeb/la, and we discover that the series number for each county is “FCN+Fips code+00000000”
ACS API
# Set the library and install the packages
library(censusapi)
library(tidycensus)
# Acquire the API by registering through https://api.census.gov/data/key_signup.html
census_api_key("your api key", install = TRUE, overwrite = TRUE)
# Acquire the API by registering through https://api.census.gov/data/key_signup.html
#The main function to retrive the data here are https://cran.r-project.org/web/packages/tidycensus/tidycensus.pdf
#to check the name of the variable
<- load_variables(2015, "acs5", cache = TRUE)
v15 View(v15)
# for example, if I want to know the age
# here is the explanation of the codebook: https://data.census.gov/table/ACSDT5Y2022.B01001
<- get_acs(geography = "county",
nc_acs_2015 year = 2015,
variables = c(age = "B01001A_003"),
state = "NC",
survey = "acs5",
output = "wide")