Code
library(tidyverse)
library(lubridate)
library(summarytools)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Joseph Vincent
March 22, 2023
# A tibble: 6 × 10
Year Month Day Federal Fu…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1954 7 1 NA NA NA 0.8 4.6 5.8 NA
2 1954 8 1 NA NA NA 1.22 NA 6 NA
3 1954 9 1 NA NA NA 1.06 NA 6.1 NA
4 1954 10 1 NA NA NA 0.85 8 5.7 NA
5 1954 11 1 NA NA NA 0.83 NA 5.3 NA
6 1954 12 1 NA NA NA 1.28 NA 5 NA
# … with abbreviated variable names ¹`Federal Funds Target Rate`,
# ²`Federal Funds Upper Target`, ³`Federal Funds Lower Target`,
# ⁴`Effective Federal Funds Rate`, ⁵`Real GDP (Percent Change)`,
# ⁶`Unemployment Rate`, ⁷`Inflation Rate`
No | Variable | Stats / Values | Freqs (% of Valid) | Graph | Missing | ||||
---|---|---|---|---|---|---|---|---|---|
1 | Year [numeric] |
|
64 distinct values | 0 (0.0%) | |||||
2 | Month [numeric] |
|
12 distinct values | 0 (0.0%) | |||||
3 | Day [numeric] |
|
29 distinct values | 0 (0.0%) | |||||
4 | Federal Funds Target Rate [numeric] |
|
63 distinct values | 442 (48.9%) | |||||
5 | Federal Funds Upper Target [numeric] |
|
4 distinct values | 801 (88.6%) | |||||
6 | Federal Funds Lower Target [numeric] |
|
4 distinct values | 801 (88.6%) | |||||
7 | Effective Federal Funds Rate [numeric] |
|
466 distinct values | 152 (16.8%) | |||||
8 | Real GDP (Percent Change) [numeric] |
|
113 distinct values | 654 (72.3%) | |||||
9 | Unemployment Rate [numeric] |
|
71 distinct values | 152 (16.8%) | |||||
10 | Inflation Rate [numeric] |
|
106 distinct values | 194 (21.5%) |
Generated by summarytools 1.0.1 (R version 4.2.2)
2023-03-22
This data shows the history of the Federal Funds Rate from 1954-2017.
It also includes the Fed’s target rates; however, it appears target rates were not set until 1958 as this data is missing.
The data set also includes other economic metrics, including inflation rate, unemployment rate, and percent change in real GDP. Inflation data is not included until October of 1982. It’s also worth noting that this type of data is only available on the 1st day of each month. Percent change in GDP is only available quarterly.
From 2009 onwards, presumably in response to the financial crisis, the Fed changed their targets to a range. Data from this point onwards includes an upper target and a lower target rate.
There are a few things to change in this data set in order to perform analysis.
First, we’ll remove any days of data that are not on the 1st of the month, as they won’t provide and inflation or unemployment data to compare against.
Second, presuming we’re interested in analyzing the Fed rate alongside Inflation (which is what the Fed rate is attempting to control) we’ll remove the data before October 1982, as this excluded inflation rate.
Finally, we’ll just remove the last row as it was missing data.
# filtering out dates before 1982, when target rate was implemented
# filtering only days on 1st of month, when inflation and unemployment is included
# removing last row with missing data
fed_rates_tidy <- fed_rates %>%
filter(Year >= 1982 & Day == 1)
fed_rates_tidy <- fed_rates_tidy[-c(1:9, 423),]
#sanity checking that Years < 1982 and Days other than 1 have been removed properly
unique(fed_rates_tidy$Year)
[1] 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
[16] 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
[31] 2012 2013 2014 2015 2016 2017
[1] 1
As you can see, the years now range from 1982 to 2017, and “1” is the only unique day in the dataset.
There are some still some issues with the data before it can be analyzed.
First, the separate Year, Month, and Day columns should be mutated into a single Date column of the same format.
Next, we haven’t addressed the change in target system in 2009. In order to continue to include this in the data set, what we can do is treat the upper limit as the target rate from this point onwards. This will allow for better visualizations of target rate over time.
Additionally, since the effectiveness of the Fed at hitting their target is something that will likely be analyzed, we’ll create a new column that easily shows the difference between the target rate and effective rate at any given date.
# mutating seperate Year, Month, Day columns into a single date
# using 'coalesce' to mutate the NA target rate values into the upper target rate after 2009 change
# creating a 'Distance from Target' column to easily visualize how far from the Fed was from target rate at each date
fed_rates_mutated <- fed_rates_tidy %>%
mutate(Date = make_date(Year, Month, Day)) %>%
mutate(`Federal Funds Target Rate` = coalesce(`Federal Funds Target Rate`,`Federal Funds Upper Target`)) %>%
mutate("Distance From Target" = `Effective Federal Funds Rate` - `Federal Funds Target Rate`) %>%
select(Date, `Distance From Target`, `Federal Funds Target Rate`, `Federal Funds Lower Target`, `Effective Federal Funds Rate`, `Real GDP (Percent Change)`, `Unemployment Rate`, `Inflation Rate`)
#sanity checking that date is now a single column and target rate no longer has NAs > 2009
tail(fed_rates_mutated)
# A tibble: 6 × 8
Date Distance From Tar…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
<date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2016-09-01 -0.1 0.5 0.25 0.4 NA 4.9 2.2
2 2016-10-01 -0.1 0.5 0.25 0.4 1.9 4.8 2.1
3 2016-11-01 -0.09 0.5 0.25 0.41 NA 4.6 2.1
4 2016-12-01 0.0400 0.5 0.25 0.54 NA 4.7 2.2
5 2017-01-01 -0.1 0.75 0.5 0.65 NA 4.8 2.3
6 2017-02-01 -0.09 0.75 0.5 0.66 NA 4.7 2.2
# … with abbreviated variable names ¹`Distance From Target`,
# ²`Federal Funds Target Rate`, ³`Federal Funds Lower Target`,
# ⁴`Effective Federal Funds Rate`, ⁵`Real GDP (Percent Change)`,
# ⁶`Unemployment Rate`, ⁷`Inflation Rate`
---
title: "Challenge 4 - fed_rates"
author: "Joseph Vincent"
description: "More data wrangling: pivoting"
date: "03/22/2023"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_4
- fed_rates
- Joseph Vincent
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
library(lubridate)
library(summarytools)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Reading in FedFundsRate
- FedFundsRate.csv⭐⭐⭐
```{r}
fed_rates <- read_csv("_data/FedFundsRate.csv")
head(fed_rates)
#printing a summary of the data
print(summarytools::dfSummary(fed_rates,
valid.col=FALSE),
method = 'render')
```
### Briefly describe the data
This data shows the history of the Federal Funds Rate from 1954-2017.
It also includes the Fed's target rates; however, it appears target rates were not set until 1958 as this data is missing.
The data set also includes other economic metrics, including inflation rate, unemployment rate, and percent change in real GDP.
Inflation data is not included until October of 1982.
It's also worth noting that this type of data is only available on the 1st day of each month.
Percent change in GDP is only available quarterly.
From 2009 onwards, presumably in response to the financial crisis, the Fed changed their targets to a range. Data from this point onwards includes an upper target and a lower target rate.
## Tidy-ing the Data
There are a few things to change in this data set in order to perform analysis.
First, we'll remove any days of data that are not on the 1st of the month, as they won't provide and inflation or unemployment data to compare against.
Second, presuming we're interested in analyzing the Fed rate alongside Inflation (which is what the Fed rate is attempting to control) we'll remove the data before October 1982, as this excluded inflation rate.
Finally, we'll just remove the last row as it was missing data.
```{r}
# filtering out dates before 1982, when target rate was implemented
# filtering only days on 1st of month, when inflation and unemployment is included
# removing last row with missing data
fed_rates_tidy <- fed_rates %>%
filter(Year >= 1982 & Day == 1)
fed_rates_tidy <- fed_rates_tidy[-c(1:9, 423),]
#sanity checking that Years < 1982 and Days other than 1 have been removed properly
unique(fed_rates_tidy$Year)
unique(fed_rates_tidy$Day)
```
As you can see, the years now range from 1982 to 2017, and "1" is the only unique day in the dataset.
## Mutating dates and target rates
There are some still some issues with the data before it can be analyzed.
First, the separate Year, Month, and Day columns should be mutated into a single Date column of the same format.
Next, we haven't addressed the change in target system in 2009. In order to continue to include this in the data set, what we can do is treat the upper limit as the target rate from this point onwards. This will allow for better visualizations of target rate over time.
Additionally, since the effectiveness of the Fed at hitting their target is something that will likely be analyzed, we'll create a new column that easily shows the difference between the target rate and effective rate at any given date.
```{r}
# mutating seperate Year, Month, Day columns into a single date
# using 'coalesce' to mutate the NA target rate values into the upper target rate after 2009 change
# creating a 'Distance from Target' column to easily visualize how far from the Fed was from target rate at each date
fed_rates_mutated <- fed_rates_tidy %>%
mutate(Date = make_date(Year, Month, Day)) %>%
mutate(`Federal Funds Target Rate` = coalesce(`Federal Funds Target Rate`,`Federal Funds Upper Target`)) %>%
mutate("Distance From Target" = `Effective Federal Funds Rate` - `Federal Funds Target Rate`) %>%
select(Date, `Distance From Target`, `Federal Funds Target Rate`, `Federal Funds Lower Target`, `Effective Federal Funds Rate`, `Real GDP (Percent Change)`, `Unemployment Rate`, `Inflation Rate`)
#sanity checking that date is now a single column and target rate no longer has NAs > 2009
tail(fed_rates_mutated)
```