Some pre-reading

Examine the webpage “Labor Force Statistics from the Current Population Survey” to learn more about the data and forthcoming analysis: https://www.bls.gov/cps/.

Find the Series IDs here.

Read more about the Public API for the data here.

# access data and install package
# install.packages("blscrapeR")
# devtools::install_github("keberwein/blscrapeR")
library(blscrapeR)

Locate data

You can also search for data and identification tags:

# Find series ids relating to education and teachers.
black_educ <- search_ids(keyword = c("Education", "Teacher", "Black"))
head(black_educ)
## # A tibble: 1 Ă— 4
##   series_title                               series_id seasonal periodicity_code
##   <chr>                                      <chr>     <chr>    <chr>           
## 1 (Unadj) Employed - Special Education Teac… LNU02070… U        A
dim(black_educ)
## [1] 1 4
math <- search_ids(keyword = c("Math"))
head(math)
## # A tibble: 6 Ă— 4
##   series_title                               series_id seasonal periodicity_code
##   <chr>                                      <chr>     <chr>    <chr>           
## 1 (Unadj) Employment Level - Computer And M… LNU02032… U        M               
## 2 (Unadj) Employment Level - Computer And M… LNU02032… U        Q               
## 3 (Unadj) Employment Level - Computer And M… LNU02032… U        M               
## 4 (Unadj) Employment Level - Computer And M… LNU02032… U        Q               
## 5 (Unadj) Employment Level - Computer And M… LNU02032… U        M               
## 6 (Unadj) Employment Level - Computer And M… LNU02032… U        Q
dim(math)
## [1] 164   4
teach <- search_ids(keyword = c("Teacher"))
head(teach)
## # A tibble: 6 Ă— 4
##   series_title                               series_id seasonal periodicity_code
##   <chr>                                      <chr>     <chr>    <chr>           
## 1 (Unadj) Employed - Postsecondary Teachers  LNU0201A… U        A               
## 2 (Unadj) Employed - Other Teachers And Ins… LNU0201A… U        A               
## 3 (Unadj) Employed - Postsecondary Teachers… LNU0201A… U        A               
## 4 (Unadj) Employed - Postsecondary Teachers… LNU0201A… U        A               
## 5 (Unadj) Employed - Postsecondary Teachers… LNU0201A… U        A               
## 6 (Unadj) Employed - Postsecondary Teachers… LNU0201A… U        A
dim(teach)
## [1] 204   4

We can then search online to find out more information. By googline the results, in this case “Employed - Special Education Teachers, Percent of Employed by Occupation, Black Or African American” we get the following information: https://data.bls.gov/dataViewer/view/timeseries/LNU02070611.

df1 <- quick_unemp_rate()
## REQUEST_SUCCEEDED
head(df1, 5)
## # A tibble: 5 Ă— 7
##    year period periodName latest value footnotes seriesID   
##   <dbl> <chr>  <chr>      <chr>  <dbl> <chr>     <chr>      
## 1  2024 M11    November   true     4.2 ""        LNS14000000
## 2  2024 M10    October    <NA>     4.1 ""        LNS14000000
## 3  2024 M09    September  <NA>     4.1 ""        LNS14000000
## 4  2024 M08    August     <NA>     4.2 ""        LNS14000000
## 5  2024 M07    July       <NA>     4.3 ""        LNS14000000
# Grab several data sets from the BLS.
# EMPLOYMENT LEVEL - Employed - Special Education Teachers - LNU02070611
# UNEMPLOYMENT LEVEL - Civilian labor force - LNS13000000
# UNEMPLOYMENT RATE - Civilian labor force - LNS14000000
df2 <- bls_api(c("LNU02070611", "LNS13000000", "LNS14000000"),
              startyear = 2010, endyear = 2023, Sys.getenv("BLS_KEY")) %>%
    # Add time-series dates
    dateCast()
## REQUEST_SUCCEEDED
# Plot employed special education teachers who identify as Black or African American
library(ggplot2)
gg1200 <- subset(df2, seriesID=="LNU02070611")
library(ggplot2)
ggplot(gg1200, aes(x=date, y=value)) +
    geom_line() +
    labs(title = "Employed - Special education teachers, Percent of employed by occupation, Black or African American")

library(ggplot2)

gg1200 <- subset(df2, seriesID == "LNU02070611")

ggplot(gg1200, aes(x = date, y = value)) +
  geom_line(color = "gray60") +
  geom_smooth(method = "loess", se = FALSE, color = "blue") +
  labs(
    title = "Employed - Special Education Teachers",
    subtitle = "Percent of employed by occupation, Black or African American",
    x = "Date",
    y = "Percentage"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(size = 12, color = "gray30")
  )
## `geom_smooth()` using formula = 'y ~ x'