Harold Nelson
2026-11-10
Our goal is to create an anlysis file focusing on the values of economic indicators for every presidential term beginning with Ronald Reagan in the first quarter of 1981 and ending with the second term of Donald Trump through the third quarter of 2026.
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Use the Import Dataset utility and select the readr option. Run str() to verify that the first column is a date and the second column is a string.
## Rows: 183 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Date, President
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Use the code I supplied in class with your own API key to create the vector unrate.
Make the following changes:
Make the observations start January 1981.
Make the observations end September 2026.
Run str on unratef to verify your work.
Use cbind to create the dataframe indicators from the vector unrate and the Presidents dataframe.
Run str() to verify.
## 'data.frame': 183 obs. of 3 variables:
## $ Date : chr "1/1/81" "4/1/81" "7/1/81" "10/1/81" ...
## $ President: chr "Reagan" "Reagan" "Reagan" "Reagan" ...
## $ unrate : num 7.4 7.4 7.4 8.2 8.8 9.4 9.9 10.7 10.4 10.1 ...
Repeat the process above to add the following variables
Run str() to verify your work.
realgdp the series_id = “A191RL1Q225SBEA”.
newjobs series_id = “PAYEMS”
newjobsf = fredr_series_observations(
series_id = "PAYEMS",
observation_start = start,
observation_end = end,
frequency = "q",
units = "chg")
newjobs = newjobsf$value
indicators = cbind(indicators,newjobs)
str(indicators)## 'data.frame': 183 obs. of 5 variables:
## $ Date : chr "1/1/81" "4/1/81" "7/1/81" "10/1/81" ...
## $ President: chr "Reagan" "Reagan" "Reagan" "Reagan" ...
## $ unrate : num 7.4 7.4 7.4 8.2 8.8 9.4 9.9 10.7 10.4 10.1 ...
## $ realgdp : num 8.1 -2.9 4.9 -4.3 -6.1 1.8 -1.5 0.2 5.4 9.4 ...
## $ newjobs : num 389 240 191 -399 -628 ...
infcpi series_id = “CPIAUCSL”
lfpr25_54f series_id = “LNS11300060”
lfpr25_54f = fredr_series_observations(
series_id = "LNS11300060",
observation_start = start,
observation_end = end,
frequency = "q",
units = "chg")
lfpr25_54 = lfpr25_54f$value
indicators = cbind(indicators,lfpr25_54)
str(indicators)## 'data.frame': 183 obs. of 7 variables:
## $ Date : chr "1/1/81" "4/1/81" "7/1/81" "10/1/81" ...
## $ President: chr "Reagan" "Reagan" "Reagan" "Reagan" ...
## $ unrate : num 7.4 7.4 7.4 8.2 8.8 9.4 9.9 10.7 10.4 10.1 ...
## $ realgdp : num 8.1 -2.9 4.9 -4.3 -6.1 1.8 -1.5 0.2 5.4 9.4 ...
## $ newjobs : num 389 240 191 -399 -628 ...
## $ infcpi : num 11.53 8.6 11.61 6.66 3.6 ...
## $ lfpr25_54: num 0.3667 0.3333 -0.3 0.3333 0.0667 ...
Save the dataframe as an Rdata file.