Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Code to graph Taylor/Mankiw rule approximations to Fed Rate - /u/MetricT
- library(tidyverse)
- library(fredr)
- library(purrr)
- library(scales)
- # Set FRED API key to access the FRED database.
- # You may request an API key at:
- # https://research.stlouisfed.org/useraccount/apikeys
- fredr_set_key(api_key_fred)
- ### What are the start/end dates you wish to graph
- date_start <- as.Date("1949-01-01") # <- Earliest date
- date_start <- as.Date("2000-01-01")
- date_end <- as.Date(Sys.Date())
- ### Data to load from FRED
- fred_series <-
- tribble(
- ~ series_id, ~frequency, ~units,
- "GDP", "q", "lin", # Nominal GDP
- "GDPC1", "q", "lin", # Real GDP
- "GDPPOT", "q", "lin", # Potential GDP
- "GDPDEF", "q", "pc1", # Gross Domestic Product: Implicit Price Deflator
- "CPILFESL", "m", "pc1", # Consumer Price Index for All Urban Consumers: All Items Less Food and Energy in U.S. City Average
- "UNRATE", "m", "lin", # Unemployment Rate
- "FEDFUNDS", "m", "lin", # Federal Funds Rate
- )
- # Use purrr to pull all of the series from FRED
- data_fred <-
- purrr::pmap_dfr(.l = fred_series, .f = fredr) %>%
- select(date, series_id, value) %>%
- pivot_wider(id_cols = "date", names_from = "series_id", values_from = "value") %>%
- arrange(date)
- # Filter data to the time window specified
- data_fred <- data_fred %>% filter(date >= date_start & date <= date_end)
- # Compute the Taylor/Mankiw Rule estimates
- data_fred <-
- data_fred %>%
- mutate(Taylor_Rule = GDPDEF + 2 + 0.5 * (GDPDEF - 2) + 0.5 * ((GDPC1 - GDPPOT) / GDPPOT) * 100) %>%
- # Compute Mankiw rule using constants from Mankiw's original paper at
- # http://scholar.harvard.edu/files/mankiw/files/us_monetary_policy_during_the_1990s.pdf
- # mutate(Mankiw_Rule = 8.5 + 1.4 * (CPILFESL - UNRATE))
- # Compute Mankiw rule using updated constants by Lars Christensen
- # at https://marketmonetarist.com/2014/09/16/mankiw-rule-tells-the-fed-to-tighten/
- mutate(Mankiw_Rule = 9.1 + 2.1 * (CPILFESL - UNRATE))
- ##########################################################################
- ### Graph: Taylor Rule, Mankiw Rule, and Fed Rate
- ##########################################################################
- c1 <- "U.S. Bureau of Economic Analysis, Real Gross Domestic Product [GDPC1]\n"
- c2 <- "U.S. Congressional Budget Office, Real Potential Gross Domestic Product [GDPPOT]\n"
- c3 <- "U.S. Bureau of Economic Analysis, Gross Domestic Product: Implicit Price Deflator [GDPDEF]\n"
- c4 <- "U.S. Bureau of Labor Statistics, Consumer Price Index for All Urban Consumers: All Items Less Food and Energy in U.S. City Average [CPILFESL]\n"
- c5 <- "U.S. Bureau of Labor Statistics, Unemployment Rate [UNRATE]\n"
- c6 <- "Board of Governors of the Federal Reserve System (US), Effective Federal Funds Rate [FEDFUNDS]\n"
- c7 <- "retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org\n"
- c8 <- paste("Data retrieved on", format(Sys.time(), "%B %d, %Y at %I:%M %p %Z"))
- caption <- "" #paste(c1, c2, c3, c4, c5, c6, c7, c8)
- # Initialize the plot
- p_mankiw_taylor <-
- ggplot() +
- theme_bw() +
- theme(legend.title = element_blank()) +
- theme(legend.position = "bottom") +
- # Plot the Fed Rate
- geom_line(data = data_fred, size = 1.3, aes(x = date, y = FEDFUNDS/ 100, color = "Federal Funds Rate")) +
- # Plot the Taylor rule
- geom_line(data = data_fred %>% filter(!is.na(Taylor_Rule)), size = 1.3, aes(x = date, y = Taylor_Rule / 100, color = "Taylor Rule")) +
- # Plot the Mankiw rule
- geom_line(data = data_fred %>% filter(!is.na(Mankiw_Rule)), size = 1.3, aes(x = date, y = Mankiw_Rule / 100, color = "Mankiw Rule")) +
- geom_hline(yintercept = 0, linetype = "dotted") +
- scale_y_continuous(breaks = pretty_breaks(7), labels = scales::percent_format(accuracy = 1)) +
- scale_x_date(breaks = pretty_breaks(8)) +
- scale_colour_manual(values = c("Federal Funds Rate" = "steelblue2",
- "Taylor Rule" = "goldenrod",
- "Mankiw Rule" = "red3"
- )) +
- # Set the title, subtitle, captions, xlab, and ylab
- labs(title = "Taylor Rule, Mankiw Rule, and Fed Rate",
- subtitle = "Recessions marked with vertical bars",
- caption = caption, x = "", y = "")
- print(p_mankiw_taylor)
Add Comment
Please, Sign In to add comment