Story - 2 : Can the FED Control Inflation and Maintain Full Employment

I am usimng fedr package to use API to get the Economic Data for this assignment. The API is public and very easy to set up the connection.

Instruction avalilable on how to load the data here https://github.com/sboysel/fredr

# load library 
library(fredr)
library(fredr)

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## âś” dplyr     1.1.4     âś” readr     2.1.5
## âś” forcats   1.0.0     âś” stringr   1.5.1
## âś” ggplot2   3.5.1     âś” tibble    3.2.1
## âś” lubridate 1.9.3     âś” tidyr     1.3.1
## âś” purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## âś– dplyr::filter() masks stats::filter()
## âś– dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Hide Your API

The goal of the data collection was to gather 25 years of historical data for the Consumer Price Index (CPI), Federal Funds Rate (FRED), Unemployment Rate, and Inflation Rate. Data for the CPI and Unemployment Rate were sourced from the Bureau of Labor Statistics (BLS), while the Federal Funds Rate and Inflation Rate were obtained from the Federal Reserve Board’s website. This required utilizing two different APIs. Due to the BLS’s policy of limiting data requests to a maximum of 20 years, the code had to be adjusted to combine two separate requests to cover the 25-year span for each dataset. On the other hand, data retrieval from the Federal Reserve Board was streamlined using the fredr package, which made the process straightforward once an API key was acquired.

# Hide Your API
FRED_API_KEY=readLines('api.txt')

fredr_set_key(FRED_API_KEY)



# Fetch UnEmployment Rate for the past 25 years
unrate_data <- fredr(
  series_id = "UNRATE",
  observation_start = as.Date("1999-01-01"),
  observation_end = as.Date("2024-09-22")
)

# Fetch Consumer Price Index 

cpi_data <- fredr(
  series_id = "CPIAUCNS",
  observation_start = as.Date("1999-01-01"),
  observation_end = as.Date("2024-09-22"))



# Fetch Fed Data
fed_data <- fredr(
  series_id = "FEDFUNDS",
  observation_start = as.Date("1999-01-01"),
  observation_end = as.Date("2024-09-22"))
# Fetch fed fun target 
fed_target_data <- fredr(
  series_id = "DFEDTARU",
  observation_start = as.Date("1999-01-01"),
  observation_end = as.Date("2024-09-22"))

recession <- fredr(
  series_id = 'JHDUSRGDPBR',
  observation_start = as.Date('1999-01-01'),
  observation_end = as.Date('2024-09-22')
)

# Fetch Inflation Rate
inflation_data <- fredr(
  series_id = "FPCPITOTLZGUSA",
  observation_start = as.Date("1999-01-01"),
  observation_end = as.Date("2024-09-22"))

The graph titled “Trends of Inflation, Fed, and Unemployment Rate” illustrates the interplay between three critical economic indicators—inflation rate, federal funds rate, and unemployment rate—over a timeline from 2000 to 2020. The X-axis represents the dates, while the Y-axis indicates rates ranging from 0 to 15. The inflation rate (red line) fluctuates within a moderate range, while the federal funds rate (green line) exhibits significant variations, particularly during economic downturns. The unemployment rate (blue line) shows notable spikes during recessions, including the 2001, 2008, and 2020 recessions, marked by rising unemployment and declining federal funds rates. This graph highlights a consistent correlation during recession periods, where the unemployment rate increases, the federal funds rate decreases, and the inflation rate varies in response. It underscores the impact of policy adjustments, particularly in managing economic stability during times of stress. Overall, the visualization effectively captures the complex interactions among these key economic indicators.

# Assuming unrate_data and inflation_data are available and have similar structures
# Ensure that both datasets have a 'date' and 'value' column for plotting

# Merge the datasets by date for easy plotting

# Ensure that 'date' is in Date format
inflation_data$date <- as.Date(inflation_data$date)
cpi_data$date <- as.Date(cpi_data$date)
unrate_data$date <- as.Date(unrate_data$date)
fed_data$date <- as.Date(fed_data$date)
recession$date <- as.Date(recession$date)

# Create an empty plot with the range of all three datasets
plot(inflation_data$date, inflation_data$value, type = "l", col = "red", ylim = range(c(inflation_data$value, fed_data$value, unrate_data$value)), 
     xlab = "Date", ylab = "Rate", main = "Trends of Inflation, Fed Funds, and Unemployment Rate")

# Add lines for cpi_data and unrate_data
lines(fed_data$date, fed_data$value, col = "blue")
lines(unrate_data$date, unrate_data$value, col = "green")

# Add a legend to differentiate the lines
legend("topright", legend = c("Inflation Rate", "Fed Funds", "Unemployment Rate"), col = c("red", "blue", "green"), lty = 1, xpd=TRUE)


# Add vertical lines to indicate recession periods
recession_dates <- c(as.Date("2001-03-01"), as.Date("2008-12-01"), as.Date("2020-03-01"))

# Draw vertical lines at recession start dates
abline(v = recession_dates, col = "grey", lwd = 2, lty = 2)  # grey dashed lines for recessions


###################

# Get the middle of the y-axis for label placement
y_mid <- (par("usr")[3] + par("usr")[4]) / 2  # Middle of the y-range

# Shift the labels upwards (closer to the top but not at the top)
y_label_position <- y_mid + (par("usr")[4] - y_mid) * 0.25  # Adjust upwards

# Add labels slightly above the middle of the plot
text(x = recession_dates, y = y_label_position, labels = c(" 2001 Recession", "2008 Recession", "2020 Recession"), 
     pos = 3, col = "red")

The graph below illustrates the yearly percentage changes in key economic indicators from 1999 to 2024. The graph tracks the inflation rate, personal consumption expenditures, unemployment rate, and consumer price index. Notable spikes are evident around 2000, 2008, and 2020, corresponding to the dot-com recession, the housing market recession, and the COVID-19 recession, respectively.It highlights the dramatic changes during these economic downturns.

The graph shows the trends in five key economic indicators: Inflation Rate Change, CPI Rate, Fed Target Change, and Fed Funds Change, with recession periods marked by vertical blue lines around 2001 and 2008. The data indicates that while the Federal Reserve has actively adjusted its rates in response to economic downturns, achieving price stability has been a challenge, particularly in recent years post-2015. The CPI and Inflation Rate Change exhibit volatility, especially with noticeable upward trends, suggesting inflationary pressures are building. Conversely, the Fed Funds Rate and Fed Target Rate show relative stability, indicating the Fed’s efforts to stimulate economic activity following recessions. Overall, while the Fed has made significant interventions to fulfill its dual mandate of maintaining price stability and maximizing employment, recent fluctuations in inflation rates highlight ongoing challenges in effectively managing these economic goals.

# Function to calculate percentage change from previous year
# Function to calculate percentage change from previous year
calculate_pct_change <- function(data) {
  data %>%
    arrange(date) %>%
    mutate(year = year(date)) %>%
    group_by(year) %>%
    summarise(value = mean(value, na.rm = TRUE)) %>%
    ungroup() %>%
    mutate(pct_change = (value / lag(value) - 1) * 100) %>%
    filter(!is.na(pct_change))
}

## Calculate percentage change for each data set
unrate_pct_change <- calculate_pct_change(unrate_data)
unrate_pct_change <-  unrate_pct_change %>% filter(!is.infinite(pct_change))
cpi_pct_change <- calculate_pct_change(cpi_data)
cpi_pct_change <-  cpi_pct_change %>% filter(!is.infinite(pct_change))
fed_data_change <- calculate_pct_change(fed_data)
fed_data_change <-  fed_data_change %>% filter(!is.infinite(pct_change))
fed_target_pct_change <- calculate_pct_change(fed_target_data)
fed_target_pct_change <-  fed_target_pct_change %>% filter(!is.infinite(pct_change))
                                                           
inflation_pct_change <- calculate_pct_change(inflation_data)
inflation_pct_change <-  inflation_pct_change %>% filter(!is.infinite(pct_change))
recession_pct_change <- calculate_pct_change(recession)
recession_pct_change <-  recession_pct_change %>% filter(!is.infinite(pct_change))


# Create the base plot for the first dataset
plot(recession_pct_change$year, recession_pct_change$pct_change,type = "l",  col = "blue", lwd = 2,
     xlab = "Year", ylab = "Percentage of Change", 
     ylim = range(c(scale(inflation_pct_change$pct_change), 
                    scale(cpi_pct_change$pct_change), 
                    scale(fed_data_change$pct_change), 
                    scale(fed_target_pct_change$pct_change),
                    scale(inflation_pct_change$pct_change))),  # Make sure all datasets are included and parentheses are closed
     main = "Inflation Rate Change and Impact over Year")

# Adding other lines to the plot
lines(cpi_pct_change$year, scale(cpi_pct_change$pct_change), col = "red", lwd = 2)
#lines(fed_data_change$year, scale(fed_data_change$pct_change), col = "green", lwd = 2)
lines(fed_target_pct_change$year, scale(fed_target_pct_change$pct_change), col = "purple", lwd = 2)
lines(fed_data_change$year, scale(fed_data_change$pct_change), col = "orange", lwd = 2)
lines(inflation_pct_change$year, scale(inflation_pct_change$pct_change), col = "grey", lwd = 2)

# Add a legend to differentiate between the datasets
legend("topright", legend = c("Recession ", "CPI Rate",  "Fed Target Change", "Fed Funds Change","Inflation Rate Change"),
       col = c("blue", "red",  "purple", "orange","grey"), lty = 1, lwd = 2)

We can say that FED has faced significant challenges, particularly during major economic downturns, the overall trend suggests that it has made substantial efforts to fulfill its mandate.The ability to reduce unemployment and control inflation after economic shocks indicates a level of success in promoting maximum employment and stable prices. However, the sharp increases towards 2024 in both rates highlight ongoing challenges that the FED continues to address. Yes FED has managed to both employment and inflation rates over time. However, the sharp increases towards 2024 indicate ongoing challenges that the FED continues to address.