challenge_4
FederalFundsRate
Author

Emma Rasmussen

Published

August 18, 2022

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",
                        show_col_types = FALSE)
#Saving an unchanged copy of the dataset
FedFundsRateOrig<-FedFundsRate

#checking variables
colnames(FedFundsRate)
 [1] "Year"                         "Month"                       
 [3] "Day"                          "Federal Funds Target Rate"   
 [5] "Federal Funds Upper Target"   "Federal Funds Lower Target"  
 [7] "Effective Federal Funds Rate" "Real GDP (Percent Change)"   
 [9] "Unemployment Rate"            "Inflation Rate"              
Code
#Checking columns with a lot of NA values
FedFundsRate%>%
  select("Federal Funds Target Rate", "Federal Funds Upper Target", "Federal Funds Lower Target") %>% 
  distinct()
# A tibble: 68 × 3
   `Federal Funds Target Rate` `Federal Funds Upper Target` Federal Funds Lowe…¹
                         <dbl>                        <dbl>                <dbl>
 1                       NA                              NA                   NA
 2                       10.2                            NA                   NA
 3                       10                              NA                   NA
 4                        9.5                            NA                   NA
 5                        9                              NA                   NA
 6                        8.5                            NA                   NA
 7                        8.62                           NA                   NA
 8                        8.75                           NA                   NA
 9                        9.25                           NA                   NA
10                        9.44                           NA                   NA
# … with 58 more rows, and abbreviated variable name
#   ¹​`Federal Funds Lower Target`
# ℹ Use `print(n = ...)` to see more rows
Code
#renaming columns prior to pivot
FedFundsRate<-rename(FedFundsRate, "TargetRate"="Federal Funds Target Rate", "UpperTargetRate"="Federal Funds Upper Target", "LowerTargetRate"="Federal Funds Lower Target", "EffectiveRate"="Effective Federal Funds Rate", "GDP(PercentChange)"="Real GDP (Percent Change)", "UnemploymentRate"="Unemployment Rate", "InflationRate"="Inflation Rate")

FedFundsRate
# A tibble: 904 × 10
    Year Month   Day TargetRate UpperT…¹ Lower…² Effec…³ GDP(P…⁴ 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 ¹​UpperTargetRate,
#   ²​LowerTargetRate, ³​EffectiveRate, ⁴​`GDP(PercentChange)`, ⁵​UnemploymentRate,
#   ⁶​InflationRate
# ℹ Use `print(n = ...)` to see more rows

Briefly describe the data

I know nothing about economics but the Federal Funds Rate appears to be set by the government to regulate lending by banks. The Federal Open Markets Committee (FOMC) sets an upper and lower limit target for the Federal Funds Rate. This data set includes a target rate, these upper and lower target limits, and the effective rate (I am assuming these are independent variables). So one observation includes: date, target rate, upper and lower limits, and effective rate). The data set also includes the GDP, Unemployment Rate, and inflation which I am assuming to be dependent variables because they are effected by the federal funds rate.

Tidy Data (as needed)

#Pivoting federal fund rates into a single column

Code
FedFundsRateLonger<-pivot_longer(FedFundsRate, col=c("TargetRate", "UpperTargetRate", "LowerTargetRate", "EffectiveRate"),
                                 names_to="FederalFundsRate",
                                 values_to="Value")
FedFundsRateLonger
# A tibble: 3,616 × 8
    Year Month   Day `GDP(PercentChange)` UnemploymentRate Infla…¹ Feder…² Value
   <dbl> <dbl> <dbl>                <dbl>            <dbl>   <dbl> <chr>   <dbl>
 1  1954     7     1                  4.6              5.8      NA Target… NA   
 2  1954     7     1                  4.6              5.8      NA UpperT… NA   
 3  1954     7     1                  4.6              5.8      NA LowerT… NA   
 4  1954     7     1                  4.6              5.8      NA Effect…  0.8 
 5  1954     8     1                 NA                6        NA Target… NA   
 6  1954     8     1                 NA                6        NA UpperT… NA   
 7  1954     8     1                 NA                6        NA LowerT… NA   
 8  1954     8     1                 NA                6        NA Effect…  1.22
 9  1954     9     1                 NA                6.1      NA Target… NA   
10  1954     9     1                 NA                6.1      NA UpperT… NA   
# … with 3,606 more rows, and abbreviated variable names ¹​InflationRate,
#   ²​FederalFundsRate
# ℹ Use `print(n = ...)` to see more rows

Any additional comments?

If I knew how the data was being used/type of analyses we were doing I might pivot differently

Identify variables that need to be mutated

Code
#reformatting date
FedFundsRateLonger$Date<- paste(FedFundsRateLonger$Year, FedFundsRateLonger$Month, FedFundsRateLonger$Day, sep="-") %>% 
  ymd() %>% 
  as.Date()

#removing date columns and reordering columns for readability: date-rate-value-Dependent Variables
select(FedFundsRateLonger, 9,7,8,6,5,4)
# A tibble: 3,616 × 6
   Date       FederalFundsRate Value InflationRate UnemploymentRate GDP(Percen…¹
   <date>     <chr>            <dbl>         <dbl>            <dbl>        <dbl>
 1 1954-07-01 TargetRate       NA               NA              5.8          4.6
 2 1954-07-01 UpperTargetRate  NA               NA              5.8          4.6
 3 1954-07-01 LowerTargetRate  NA               NA              5.8          4.6
 4 1954-07-01 EffectiveRate     0.8             NA              5.8          4.6
 5 1954-08-01 TargetRate       NA               NA              6           NA  
 6 1954-08-01 UpperTargetRate  NA               NA              6           NA  
 7 1954-08-01 LowerTargetRate  NA               NA              6           NA  
 8 1954-08-01 EffectiveRate     1.22            NA              6           NA  
 9 1954-09-01 TargetRate       NA               NA              6.1         NA  
10 1954-09-01 UpperTargetRate  NA               NA              6.1         NA  
# … with 3,606 more rows, and abbreviated variable name ¹​`GDP(PercentChange)`
# ℹ Use `print(n = ...)` to see more rows

Any additional comments?

I left the unemployment rate, inflation rate, and GDP in their own columns so analyses on these data could more easily compare Federal Funds Rate against these dependent variables over time (i.e. filtering effective rate and comparing to one of these variables). Condensing the data into one rate and variable might be easier to answer specific questions, but I did not want to remove any data.