challenge_6
fed rates
debt
Author

Thrishul

Published

April 5, 2023

Code
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.4     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
Code
library(ggplot2)
library(readxl)
library(lubridate)

Attaching package: 'lubridate'

The following objects are masked from 'package:base':

    date, intersect, setdiff, union
Code
library(here)
Warning: package 'here' was built under R version 4.2.3
here() starts at C:/Users/polat/OneDrive/Documents/GitHub/dacssqa/601_Spring_2023
Code
source(here("posts","umass_colors.R"))
Warning in file(filename, "r", encoding = encoding): cannot open file
'C:/Users/polat/OneDrive/Documents/GitHub/dacssqa/601_Spring_2023/posts/umass_colors.R':
No such file or directory
Error in file(filename, "r", encoding = encoding): cannot open the connection
Code
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Today’s challenge is to:

create at least one graph including time (evolution) try to make them “publication” ready (optional) Explain why you choose the specific graph type Create at least one graph depicting part-whole or flow relationships try to make them “publication” ready (optional) Explain why you choose the specific graph type

Dataset Description

The dataset spans from July 1954 to March 2017 and comprises daily macroeconomic indicators associated with the effective federal funds rate. This rate refers to the interest rate at which banks lend money to each other to fulfill mandated reserve requirements. In addition to the date column, the dataset contains seven variables, four of which pertain to the federal funds rate (target, upper target, lower target, and effective). The remaining three variables represent macroeconomic indicators such as inflation, GDP change, and unemployment rate.

Code
fed_rates_vars<-here("posts","_data","FedFundsRate.csv") %>% 
  read_csv(n_max = 1,
           col_names = NULL)%>%
  select(-c(X1:X3))%>%
  unlist(.)

names(fed_rates_vars) <-c("fed_target", "fed_target_upper",
                         "fed_target_lower", "fed_effective",
                         "gdp_ch", "unemploy", "inflation")
      
fed_rates_orig<-here("posts","_data","FedFundsRate.csv") %>% 
  read_csv(skip=1,
           col_names = c("Year", "Month", "Day", 
                         names(fed_rates_vars)))

fed_rates<-fed_rates_orig%>%
  mutate(date = make_date(Year, Month, Day))%>%
  select(-c(Year, Month, Day))

fed_rates <- fed_rates%>%
  pivot_longer(cols=-date, 
               names_to = "variable",
               values_to = "value")

Next, we aimed to visualize the evolution of the macroeconomic indicators and federal funds rate over time, while carefully handling the issue of missing data.

Code
fed_rates%>%
  filter(str_starts(variable, "fed"))%>%
ggplot(., aes(x=date, y=value, color=variable))+
  geom_point(size=0)+
  geom_line()+
  scale_y_continuous(labels = scales::label_percent(scale = 1))

By analyzing the plotted data, it becomes apparent how closely the effective rate follows the target rate, and how the Federal Reserve adjusted its approach to target rate setting in response to the 2009 financial crisis. To gain additional insights, we explored the relationship between the effective rate and one of the other macroeconomic indicators.

Code
fed_rates%>%
  filter(variable%in%c("fed_effective", "gdp_ch", 
                       "unemploy", "inflation"))%>%
ggplot(., aes(x=date, y=value, color=variable))+
  geom_point(size=0)+
  geom_line()+
  facet_grid(rows = vars(variable))

Code
year_unemploy <- fed_rates %>%
  pivot_wider(names_from = variable, values_from = value) %>%
  mutate(year=year(date)) %>%
  group_by(year) %>%
  summarise(median_rate=median(unemploy)/100) %>%
  ungroup()
year_unemploy
# A tibble: 64 × 2
    year median_rate
   <dbl>       <dbl>
 1  1954      0.0575
 2  1955      0.0425
 3  1956      0.0415
 4  1957      0.042 
 5  1958      0.069 
 6  1959      0.054 
 7  1960      0.0545
 8  1961      0.068 
 9  1962      0.0555
10  1963      0.0565
# … with 54 more rows
Code
year_unemploy %>%
  ggplot(aes(year,median_rate))+
  geom_line()

Code
year_unemploy %>%
  filter(year<=1981) %>%
  ggplot(aes(year,median_rate))+
  geom_line()+
  scale_y_continuous(labels=scales::percent_format(),limits=c(0,.1))+
  scale_x_continuous(breaks=seq(1955,1980,5))

Code
  labs(x="year",y="median unemployment rate")
$x
[1] "year"

$y
[1] "median unemployment rate"

attr(,"class")
[1] "labels"