Code
library(tidyverse)
library(dplyr)
library(summarytools)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Kristin Abijaoude
October 12, 2022
# A tibble: 904 × 10
Year Month Day Federal F…¹ 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
7 1955 1 1 NA NA NA 1.39 11.9 4.9 NA
8 1955 2 1 NA NA NA 1.29 NA 4.7 NA
9 1955 3 1 NA NA NA 1.35 NA 4.6 NA
10 1955 4 1 NA NA NA 1.43 6.7 4.7 NA
# … with 894 more rows, and 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`
Today, we are going to analyze the Federal Funds Rate dataset.
Before I get into the dataset itself, let’s first learn about what federal fund rates are. According to Investopedia and Business Insider, federal funds rates are rates that banks and credit unions charge each other before borrowing on an non-collateral basis (in other words, as an unsecured loan). The target rates are set by the Federal Open Market Committee, the policymaking body of the Federal Reserve System. This is essential to stabilize economic growth in the US.
In other words, when there is too much growth, the FOMC raise interest rates, which discourages spending, borrowing, and investing; and therefore, reduce inflation and bring economic growth under control.
On the other hand, the FOMC lowers interest rates to encourage spending, borrowing, and investing in order to expand economic power. However, when rates are too low, that opens the door to out-of-control inflation, which leads to reduce purchasing power and undermining economic growth.
In addition to federal funds rates, this dataset also measures inflation rates, unemployment rates, and changes in real GDP in percentages as well.
Variable | Stats / Values | Freqs (% of Valid) | Graph | Missing | ||||
---|---|---|---|---|---|---|---|---|
Year [numeric] |
|
64 distinct values | 0 (0.0%) | |||||
Month [numeric] |
|
12 distinct values | 0 (0.0%) | |||||
Day [numeric] |
|
29 distinct values | 0 (0.0%) | |||||
Federal Funds Target Rate [numeric] |
|
63 distinct values | 442 (48.9%) | |||||
Federal Funds Upper Target [numeric] |
|
4 distinct values | 801 (88.6%) | |||||
Federal Funds Lower Target [numeric] |
|
4 distinct values | 801 (88.6%) | |||||
Effective Federal Funds Rate [numeric] |
|
466 distinct values | 152 (16.8%) | |||||
Real GDP (Percent Change) [numeric] |
|
113 distinct values | 654 (72.3%) | |||||
Unemployment Rate [numeric] |
|
71 distinct values | 152 (16.8%) | |||||
Inflation Rate [numeric] |
|
106 distinct values | 194 (21.5%) |
Generated by summarytools 1.0.1 (R version 4.2.1)
2022-12-20
# A tibble: 904 × 8
`Date YYYY/MM/DD` Federal F…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
<chr> <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
7 1955/1/1 NA NA NA 1.39 11.9 4.9 NA
8 1955/2/1 NA NA NA 1.29 NA 4.7 NA
9 1955/3/1 NA NA NA 1.35 NA 4.6 NA
10 1955/4/1 NA NA NA 1.43 6.7 4.7 NA
# … with 894 more rows, and 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`
Here, I fill in the NAs with various values that I believe would make sense to the reader as well as myself. For example, I replace the NAs with the mean (average) in the following variables: federal funds target rate, unemployment rate, and inflation rate. Meanwhile, I replace the NAs with the highest or lowest value in upper and lower federal funds rate columns, as well as real GDP change. I specified the value replacing the NAs in the chunk below.
[1] 5.658415
#[1] 5.658415 %
#replace NAs with the mean
fedfunds$`Federal Funds Target Rate`[is.na(fedfunds$`Federal Funds Target Rate`)]<-mean.fedtarget
#replace NAs in upper federal funds target rate with 1
fedfunds$`Federal Funds Upper Target`[is.na(fedfunds$`Federal Funds Upper Target`)] <-1
#replace NAs in lower federal funds target rate with 0
fedfunds$`Federal Funds Lower Target`[is.na(fedfunds$`Federal Funds Lower Target`)] <-0
#replace NAs in real GDP change with 0
fedfunds$`Real GDP (Percent Change)`[is.na(fedfunds$`Real GDP (Percent Change)`)] <-0
#find the mean of unemployment rate
mean.unemploy <- mean(fedfunds$`Unemployment Rate`, na.rm = TRUE)
#the mean
mean.unemploy
[1] 5.979122
[1] 3.73338
# A tibble: 904 × 8
`Date YYYY/MM/DD` Federal F…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1954/7/1 5.66 1 0 0.8 4.6 5.8 3.73
2 1954/8/1 5.66 1 0 1.22 0 6 3.73
3 1954/9/1 5.66 1 0 1.06 0 6.1 3.73
4 1954/10/1 5.66 1 0 0.85 8 5.7 3.73
5 1954/11/1 5.66 1 0 0.83 0 5.3 3.73
6 1954/12/1 5.66 1 0 1.28 0 5 3.73
7 1955/1/1 5.66 1 0 1.39 11.9 4.9 3.73
8 1955/2/1 5.66 1 0 1.29 0 4.7 3.73
9 1955/3/1 5.66 1 0 1.35 0 4.6 3.73
10 1955/4/1 5.66 1 0 1.43 6.7 4.7 3.73
# … with 894 more rows, and 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`
fedfundrates <-fedfunds %>% pivot_longer(cols=c(`Effective Federal Funds Rate`, `Real GDP (Percent Change)`,`Inflation Rate`, `Unemployment Rate`),
names_to='Factor',
values_to='Rate in percentage')%>%
select(-c(`Federal Funds Target Rate`, `Federal Funds Upper Target`, `Federal Funds Lower Target`))
fedfundrates
# A tibble: 3,616 × 3
`Date YYYY/MM/DD` Factor `Rate in percentage`
<chr> <chr> <dbl>
1 1954/7/1 Effective Federal Funds Rate 0.8
2 1954/7/1 Real GDP (Percent Change) 4.6
3 1954/7/1 Inflation Rate 3.73
4 1954/7/1 Unemployment Rate 5.8
5 1954/8/1 Effective Federal Funds Rate 1.22
6 1954/8/1 Real GDP (Percent Change) 0
7 1954/8/1 Inflation Rate 3.73
8 1954/8/1 Unemployment Rate 6
9 1954/9/1 Effective Federal Funds Rate 1.06
10 1954/9/1 Real GDP (Percent Change) 0
# … with 3,606 more rows
When I pivot the columns, I end up with 3616 rows!
Error in ymd(dates): could not find function "ymd"
[1] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[16] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[31] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[46] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[61] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[76] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[91] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[106] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[121] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[136] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[151] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[166] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[181] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[196] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[211] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[226] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[241] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[256] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[271] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[286] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[301] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[316] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[331] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[346] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[361] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[376] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[391] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[406] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[421] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[436] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[451] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[466] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[481] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[496] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[511] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[526] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[541] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[556] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[571] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[586] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[601] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[616] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[631] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[646] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[661] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[676] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[691] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[706] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[721] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[736] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[751] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[766] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[781] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[796] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[811] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[826] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[841] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[856] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[871] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[886] 0.00 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.50
[901] 0.50 0.50 0.50 0.75
# effective federal fund rate vs unemployment rate chart
ggplot(data = fedfunds, aes(x= `dates`)) +
geom_line(aes(y = `Effective Federal Funds Rate`), color = "darkred") +
geom_line(aes(y = unemploy), color="darkgreen") +
geom_line(aes(y = `Federal Funds Upper Target`), color="darkblue") +
geom_line(aes(y= `Federal Funds Target Rate`), color ="purple")+
geom_line(aes(y = `Federal Funds Lower Target`), color = "black")+
geom_line(aes(y = inflation), color = "lightseagreen")+
ylab("Percentages")+
ggtitle("Effective Federal Funds Rate vfrom 1954 to 2017")
Sources:
https://www.investopedia.com/terms/f/federalfundsrate.asp
https://www.businessinsider.com/personal-finance/what-is-the-federal-funds-rate
---
title: "Challenge 4 Kristin Abijaoude"
author: "Kristin Abijaoude"
desription: "More data wrangling: pivoting"
date: "10/12/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- kristin_abijaoude
- challenge4
- challenge_4
- fed_rates
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
library(dplyr)
library(summarytools)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Read in data
```{r}
fedfunds <- read_csv("_data/FedFundsRate.csv")
fedfunds
```
### Briefly describe the data
Today, we are going to analyze the Federal Funds Rate dataset.
Before I get into the dataset itself, let's first learn about what federal fund rates are. According to Investopedia and Business Insider, federal funds rates are rates that banks and credit unions charge each other before borrowing on an non-collateral basis (in other words, as an unsecured loan). The target rates are set by the Federal Open Market Committee, the policymaking body of the Federal Reserve System. This is essential to stabilize economic growth in the US.
In other words, when there is too much growth, the FOMC raise interest rates, which discourages spending, borrowing, and investing; and therefore, reduce inflation and bring economic growth under control.
On the other hand, the FOMC lowers interest rates to encourage spending, borrowing, and investing in order to expand economic power. However, when rates are too low, that opens the door to out-of-control inflation, which leads to reduce purchasing power and undermining economic growth.
In addition to federal funds rates, this dataset also measures inflation rates, unemployment rates, and changes in real GDP in percentages as well.
```{r}
#First, let's dissect the dataset itself
print(dfSummary(fedfunds,
varnumbers = FALSE,
plain.ascii = FALSE,
style = "grid",
graph.magnif = 0.70,
valid.col = FALSE),
method = 'render',
table.classes = 'table-condensed')
```
## Tidy Data (as needed)
### Create the date variable with 'unite()' command
```{r}
#unite year, month, and day column to create a single column for date
fedfunds <- unite(fedfunds, `Year`, `Month`, `Day`, col = "Date YYYY/MM/DD", sep = "/")
fedfunds
```
### Fill in NAs with 'is.na()' command
Here, I fill in the NAs with various values that I believe would make sense to the reader as well as myself. For example, I replace the NAs with the mean (average) in the following variables: federal funds target rate, unemployment rate, and inflation rate. Meanwhile, I replace the NAs with the highest or lowest value in upper and lower federal funds rate columns, as well as real GDP change. I specified the value replacing the NAs in the chunk below.
```{r}
#find the mean of federal funds target rate
mean.fedtarget <- mean(fedfunds$`Federal Funds Target Rate`, na.rm = TRUE)
#the mean
mean.fedtarget
#[1] 5.658415 %
#replace NAs with the mean
fedfunds$`Federal Funds Target Rate`[is.na(fedfunds$`Federal Funds Target Rate`)]<-mean.fedtarget
#replace NAs in upper federal funds target rate with 1
fedfunds$`Federal Funds Upper Target`[is.na(fedfunds$`Federal Funds Upper Target`)] <-1
#replace NAs in lower federal funds target rate with 0
fedfunds$`Federal Funds Lower Target`[is.na(fedfunds$`Federal Funds Lower Target`)] <-0
#replace NAs in real GDP change with 0
fedfunds$`Real GDP (Percent Change)`[is.na(fedfunds$`Real GDP (Percent Change)`)] <-0
#find the mean of unemployment rate
mean.unemploy <- mean(fedfunds$`Unemployment Rate`, na.rm = TRUE)
#the mean
mean.unemploy
#[1] 5.979122 %
#replace NAs in unemployment rate with the mean
fedfunds$`Unemployment Rate`[is.na(fedfunds$`Real GDP (Percent Change)`)] <- mean.unemploy
#find the mean of inflation rate
mean.inflation <- mean(fedfunds$`Inflation Rate`, na.rm = TRUE)
#the mean
mean.inflation
#3.73338 %
#replae NAs in inflation with mean
fedfunds$`Inflation Rate`[is.na(fedfunds$`Inflation Rate`)] <- mean.inflation
#sanity check!
fedfunds
```
```{r}
fedfundrates <-fedfunds %>% pivot_longer(cols=c(`Effective Federal Funds Rate`, `Real GDP (Percent Change)`,`Inflation Rate`, `Unemployment Rate`),
names_to='Factor',
values_to='Rate in percentage')%>%
select(-c(`Federal Funds Target Rate`, `Federal Funds Upper Target`, `Federal Funds Lower Target`))
fedfundrates
```
When I pivot the columns, I end up with 3616 rows!
```{r}
nrow(fedfundrates)
```
## Visualizing Data
```{r}
# create data
dates <- fedfunds$`Date YYYY/MM/DD`
dates <- ymd(dates)
gdp <- fedfunds$`Real GDP (Percent Change)`
unemploy <- fedfunds$`Unemployment Rate`
inflation <- fedfunds$`Inflation Rate`
fedfunds$`Federal Funds Lower Target`
# effective federal fund rate vs unemployment rate chart
ggplot(data = fedfunds, aes(x= `dates`)) +
geom_line(aes(y = `Effective Federal Funds Rate`), color = "darkred") +
geom_line(aes(y = unemploy), color="darkgreen") +
geom_line(aes(y = `Federal Funds Upper Target`), color="darkblue") +
geom_line(aes(y= `Federal Funds Target Rate`), color ="purple")+
geom_line(aes(y = `Federal Funds Lower Target`), color = "black")+
geom_line(aes(y = inflation), color = "lightseagreen")+
ylab("Percentages")+
ggtitle("Effective Federal Funds Rate vfrom 1954 to 2017")
```
Sources:
https://www.investopedia.com/terms/f/federalfundsrate.asp
https://www.businessinsider.com/personal-finance/what-is-the-federal-funds-rate