Instructions The Federal Reserve’s mandate from Congress is to control inflation and to maintain low unemployment. These seem to be contradictory objectives.
For this story you will need to source the following data for the last 25 years;
The Consumer Price Index (CPI) (Bureau of Labor Statistics)
The FED Funds Rate (FRED) (Federal Reserve Board)
Unemployment Rate (Bureau of Labor Statistics) Your Data Visualizations should be designed to answer the question “Has the FED been able to fulfill the mandate given to it by Congress?”
library(httr)
library(tidyverse)
library(glue)
library(devtools)
Specifically for Fred
##devtools::install_github("sboysel/fredr")
library(fredr)
fredr_set_key("3caf1c25a755508f5113951857fbdc08")
api_key <- fredr_get_key()
fed_funds_data <- fredr(series_id = "DFF", frequency = "m")
Specifically for BLS Note: BLS only lets you pull
#library(devtools)
#install_github("mikeasilva/blsAPI")
bls_API <- "6f6709e6fa28438296cdd931b491200b"
blsURL <- "https://api.bls.gov/publicAPI/v2/timeseries/data/"
payload_96 <- glue('{
"seriesid":["CUUR0000SA0", "LNS14000000"],
"startyear":"1977",
"endyear":"1996",
"registrationkey":"{{bls_API}}"
}', .open="{{", .close="}}")
response_96 <- POST(blsURL,
body = payload_96,
content_type("application/json"),
encode = "json")
x_96 <- content(response_96, "text") %>% jsonlite::fromJSON()
## No encoding supplied: defaulting to UTF-8.
CPI_96 <- x_96$Results$series$data[[1]] %>% as_tibble()
UNEMP_96 <- x_96$Results$series$data[[2]] %>% as_tibble()
Series Title : All items in U.S. city average, all urban consumers, not seasonally adjusted Series ID : CUUR0000SA0 Seasonality : Not Seasonally Adjusted Survey Name : Consumer Price Index for All Urban Consumers (CPI-U) Measure Data Type : All items Area : U.S. city average Item : All items
Series Id: LNS14000000 Seasonally Adjusted Series title: (Seas) Unemployment Rate Labor force status: Unemployment rate Type of data: Percent or rate Age: 16 years and over
payload_16 <- glue('{
"seriesid":["CUUR0000SA0", "LNS14000000"],
"startyear":"1997",
"endyear":"2017",
"registrationkey":"{{bls_API}}"
}', .open="{{", .close="}}")
response_16 <- POST(blsURL,
body = payload_16,
content_type("application/json"),
encode = "json")
x_16 <- content(response_16, "text") %>% jsonlite::fromJSON()
## No encoding supplied: defaulting to UTF-8.
CPI_16 <- x_16$Results$series$data[[1]] %>% as_tibble()
UNEMP_16 <- x_16$Results$series$data[[2]] %>% as_tibble()
payload_24 <- glue('{
"seriesid":["CUUR0000SA0", "LNS14000000"],
"startyear":"2017",
"endyear":"2024",
"registrationkey":"{{bls_API}}"
}', .open="{{", .close="}}")
response_24 <- POST(blsURL,
body = payload_24,
content_type("application/json"),
encode = "json")
x_24 <- content(response_24, "text") %>% jsonlite::fromJSON()
## No encoding supplied: defaulting to UTF-8.
CPI_24 <- x_24$Results$series$data[[1]] %>% as_tibble()
UNEMP_24 <- x_24$Results$series$data[[2]] %>% as_tibble()
library(dplyr)
CPI_96_cl <- CPI_96 %>%
select(1:4)
CPI_16_cl <- CPI_16 %>%
select(1:4)
CPI_24_cl <- CPI_24 %>%
select(1:3,5)
#combine full df together
CPI_full <- bind_rows(CPI_96_cl, CPI_16_cl, CPI_24_cl)
CPI_full$value <- as.numeric(CPI_full$value)
CPI_full_cl <- CPI_full %>%
mutate(date = as.Date(paste(year, substr(period, 2, 3), "01", sep = "-"))) %>%
select(-year, -period)
UNEMP_96_cl <- UNEMP_96 %>%
select(1:4)
UNEMP_16_cl <- UNEMP_16 %>%
select(1:4)
UNEMP_24_cl <- UNEMP_24 %>%
select(1:3,5)
#combine full df together
UNEMP_full <- bind_rows(UNEMP_96_cl, UNEMP_16_cl, UNEMP_24_cl)
UNEMP_full_cl <- UNEMP_full %>%
mutate(date = as.Date(paste(year, substr(period, 2, 3), "01", sep = "-"))) %>%
select(-year, -period)
CPI_full_cl <- CPI_full_cl %>%
rename(CPI = value) %>%
select(2,3)
UNEMP_full_cl <- UNEMP_full_cl %>%
rename(UNEMP = value) %>%
select(2,3)
fed_funds_data_cl <-fed_funds_data %>%
filter(date >= as.Date("1977-01-01") & date <= as.Date("2024-08-01")) %>%
select(1,3) %>%
rename(FFR = value)
economic_ind <- CPI_full_cl %>%
full_join(UNEMP_full_cl, by = "date") %>%
full_join(fed_funds_data_cl, by = "date") %>%
select(date, CPI, UNEMP, FFR) %>%
mutate(
UNEMP = as.numeric(UNEMP),
FFR = as.numeric(FFR)) %>%
arrange(date) %>%
mutate(
inflation = (CPI - lag(CPI)) / lag(CPI) *100)
economic_ind$date <- as.Date(economic_ind$date)
par(mfrow = c(2, 1), mar = c(4, 4, 2, 1))
# Unemployment and Federal Funds
plot(economic_ind$date, economic_ind$FFR, type = "l", col = "blue",
xlab = "Date", ylab = "Combined Rates (%)", main = "Unemployment and Federal Funds Rate Over Time")
lines(economic_ind$date, economic_ind$UNEMP, type = "l", col = "red")
legend("topright", legend = c("Federal Funds Rate", "Unemployment"), col = c("blue", "red"), lty = 1, cex=0.5, bty="n")
# Inflation
plot(economic_ind$date, economic_ind$inflation, type = "l", col = "green",
xlab = "Date", ylab = "Inflation Rate (%)", main = "Inflation Rate Over Time")
legend("bottomright", legend = c("Inflation Rate"), col = c("Green"), lty = 1, cex=0.5, bty="n")