Code
library(tidyverse)
library(lubridate)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Emma Rasmussen
August 18, 2022
[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"
# 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
#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
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.
#Pivoting federal fund rates into a single column
# 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
# 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.
---
title: "Challenge 4"
author: "Emma Rasmussen"
desription: "More data wrangling: pivoting"
date: "08/18/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_4
- FederalFundsRate
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
library(lubridate)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Read in data
```{r}
FedFundsRate<-read_csv("_data/FedFundsRate.csv",
show_col_types = FALSE)
#Saving an unchanged copy of the dataset
FedFundsRateOrig<-FedFundsRate
#checking variables
colnames(FedFundsRate)
#Checking columns with a lot of NA values
FedFundsRate%>%
select("Federal Funds Target Rate", "Federal Funds Upper Target", "Federal Funds Lower Target") %>%
distinct()
#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
```
### 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
```{r}
FedFundsRateLonger<-pivot_longer(FedFundsRate, col=c("TargetRate", "UpperTargetRate", "LowerTargetRate", "EffectiveRate"),
names_to="FederalFundsRate",
values_to="Value")
FedFundsRateLonger
```
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
```{r}
#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)
```
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.