Challenge 4: Federal Funds Rate

challenge_4
Justine Shakespeare
fed_rates
More data wrangling: mutate and lubridate
Author

Justine Shakespeare

Published

March 22, 2023

Code
library(tidyverse)
library(lubridate)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Read in data

Code
FedFundsRate <- read_csv("_data/FedFundsRate.csv")
glimpse(FedFundsRate)
Rows: 904
Columns: 10
$ Year                           <dbl> 1954, 1954, 1954, 1954, 1954, 1954, 195…
$ Month                          <dbl> 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, …
$ Day                            <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
$ `Federal Funds Target Rate`    <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ `Federal Funds Upper Target`   <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ `Federal Funds Lower Target`   <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ `Effective Federal Funds Rate` <dbl> 0.80, 1.22, 1.06, 0.85, 0.83, 1.28, 1.3…
$ `Real GDP (Percent Change)`    <dbl> 4.6, NA, NA, 8.0, NA, NA, 11.9, NA, NA,…
$ `Unemployment Rate`            <dbl> 5.8, 6.0, 6.1, 5.7, 5.3, 5.0, 4.9, 4.7,…
$ `Inflation Rate`               <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…

Data description

This dataset tracks several key metrics related to the United States economy, including several variables related to the federal funds target and effective rate, the change of real GDP, and the unemployment and inflation rates. This data is tracked over a period of time, which is delineated by three variables related to the date.

Identify variables that need to be mutated

It doesn’t look as if this data needs to be tidied. But there are some additional variables we could create for ease of use. First, let’s create a variable that captures the date by using the mutate() and make_date() function and combining the three variables: Year, Month, and Day. We can reorder the variables when we print this updates dataset so that we just see the new Date column instead of the previous columns related to the date.

Code
FFR_date <- mutate(FedFundsRate, Date = make_date(Year, Month, Day))
select(FFR_date, Date, `Federal Funds Target Rate`, 
       `Federal Funds Upper Target`, `Federal Funds Lower Target`, 
       `Effective Federal Funds Rate`, `Real GDP (Percent Change)`, 
       `Unemployment Rate`, `Inflation Rate`)
# A tibble: 904 × 8
   Date       Federal Funds Ta…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
   <date>                  <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
 1 1954-07-01                 NA      NA      NA    0.8      4.6     5.8      NA
 2 1954-08-01                 NA      NA      NA    1.22    NA       6        NA
 3 1954-09-01                 NA      NA      NA    1.06    NA       6.1      NA
 4 1954-10-01                 NA      NA      NA    0.85     8       5.7      NA
 5 1954-11-01                 NA      NA      NA    0.83    NA       5.3      NA
 6 1954-12-01                 NA      NA      NA    1.28    NA       5        NA
 7 1955-01-01                 NA      NA      NA    1.39    11.9     4.9      NA
 8 1955-02-01                 NA      NA      NA    1.29    NA       4.7      NA
 9 1955-03-01                 NA      NA      NA    1.35    NA       4.6      NA
10 1955-04-01                 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`

We can see that this variable was successfully created.

It might also be interesting to create a variable that tracks the difference between the Effective Federal Funds Rate and the Federal Funds Target Rate. Let’s use the mutate() function to create a new variable called “Difference between target and effective FFR”. We’ll reorder the data again when we print the updated dataframe so that we can see this new variable.

Code
FFR_dif <- mutate(FFR_date, `Difference between target and effective FFR` = `Federal Funds Target Rate` - `Effective Federal Funds Rate`)
select(FFR_dif, Date, `Difference between target and effective FFR`, 
       `Federal Funds Target Rate`, `Federal Funds Upper Target`, 
       `Federal Funds Lower Target`, `Effective Federal Funds Rate`, 
       `Real GDP (Percent Change)`, `Unemployment Rate`, `Inflation Rate`)
# A tibble: 904 × 9
   Date       Differen…¹ Feder…² Feder…³ Feder…⁴ Effec…⁵ Real …⁶ Unemp…⁷ Infla…⁸
   <date>          <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
 1 1954-07-01         NA      NA      NA      NA    0.8      4.6     5.8      NA
 2 1954-08-01         NA      NA      NA      NA    1.22    NA       6        NA
 3 1954-09-01         NA      NA      NA      NA    1.06    NA       6.1      NA
 4 1954-10-01         NA      NA      NA      NA    0.85     8       5.7      NA
 5 1954-11-01         NA      NA      NA      NA    0.83    NA       5.3      NA
 6 1954-12-01         NA      NA      NA      NA    1.28    NA       5        NA
 7 1955-01-01         NA      NA      NA      NA    1.39    11.9     4.9      NA
 8 1955-02-01         NA      NA      NA      NA    1.29    NA       4.7      NA
 9 1955-03-01         NA      NA      NA      NA    1.35    NA       4.6      NA
10 1955-04-01         NA      NA      NA      NA    1.43     6.7     4.7      NA
# … with 894 more rows, and abbreviated variable names
#   ¹​`Difference between target and effective FFR`,
#   ²​`Federal Funds Target Rate`, ³​`Federal Funds Upper Target`,
#   ⁴​`Federal Funds Lower Target`, ⁵​`Effective Federal Funds Rate`,
#   ⁶​`Real GDP (Percent Change)`, ⁷​`Unemployment Rate`, ⁸​`Inflation Rate`

This new variable doesn’t have any data in the first rows because there is no data in the Federal Funds Target Rate column until later years. Let’s create a new dataset object that removes all of the NAs from this new variable so we can see when we start having data there.

Code
FFR_dif_NArm <- FFR_dif[complete.cases(FFR_dif$`Difference between target and effective FFR`),]
select(FFR_dif_NArm, Date, `Difference between target and effective FFR`, 
       `Federal Funds Target Rate`, `Federal Funds Upper Target`, 
       `Federal Funds Lower Target`, `Effective Federal Funds Rate`, 
       `Real GDP (Percent Change)`, `Unemployment Rate`, `Inflation Rate`)
# A tibble: 315 × 9
   Date       Differen…¹ Feder…² Feder…³ Feder…⁴ Effec…⁵ Real …⁶ Unemp…⁷ Infla…⁸
   <date>          <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
 1 1982-10-01    0.290     10         NA      NA    9.71     0.4    10.4     5.9
 2 1982-11-01    0.300      9.5       NA      NA    9.2     NA      10.8     5.3
 3 1982-12-01    0.0500     9         NA      NA    8.95    NA      10.8     4.5
 4 1983-01-01   -0.180      8.5       NA      NA    8.68     5.3    10.4     4.7
 5 1983-02-01   -0.0100     8.5       NA      NA    8.51    NA      10.4     4.7
 6 1983-03-01   -0.270      8.5       NA      NA    8.77    NA      10.3     4.7
 7 1983-04-01   -0.175      8.62      NA      NA    8.8      9.4    10.2     4.3
 8 1983-05-01   -0.00500    8.62      NA      NA    8.63    NA      10.1     3.6
 9 1983-06-01   -0.230      8.75      NA      NA    8.98    NA      10.1     2.9
10 1983-07-01   -0.370      9         NA      NA    9.37     8.1     9.4     3  
# … with 305 more rows, and abbreviated variable names
#   ¹​`Difference between target and effective FFR`,
#   ²​`Federal Funds Target Rate`, ³​`Federal Funds Upper Target`,
#   ⁴​`Federal Funds Lower Target`, ⁵​`Effective Federal Funds Rate`,
#   ⁶​`Real GDP (Percent Change)`, ⁷​`Unemployment Rate`, ⁸​`Inflation Rate`

We can see the new variable with values, starting in 1982.