MetricT

Mankiw and Taylor rule vs Fed Rate

Sep 23rd, 2021 (edited)
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 4.45 KB | None | 0 0
  1. ### Code to graph Taylor/Mankiw rule approximations to Fed Rate - /u/MetricT
  2.  
  3. library(tidyverse)
  4. library(fredr)
  5. library(purrr)
  6. library(scales)
  7.  
  8. # Set FRED API key to access the FRED database.
  9. # You may request an API key at:
  10. # https://research.stlouisfed.org/useraccount/apikeys
  11. fredr_set_key(api_key_fred)
  12.  
  13. ### What are the start/end dates you wish to graph
  14. date_start <- as.Date("1949-01-01") # <- Earliest date
  15. date_start <- as.Date("2000-01-01")
  16. date_end   <- as.Date(Sys.Date())
  17.  
  18. ### Data to load from FRED
  19. fred_series  <-
  20.   tribble(
  21.     ~ series_id,            ~frequency,  ~units,
  22.     "GDP",                  "q",         "lin", # Nominal GDP
  23.     "GDPC1",                "q",         "lin", # Real GDP
  24.     "GDPPOT",               "q",         "lin", # Potential GDP
  25.     "GDPDEF",               "q",         "pc1", # Gross Domestic Product: Implicit Price Deflator
  26.     "CPILFESL",             "m",         "pc1", # Consumer Price Index for All Urban Consumers: All Items Less Food and Energy in U.S. City Average
  27.     "UNRATE",               "m",         "lin", # Unemployment Rate
  28.     "FEDFUNDS",             "m",         "lin", # Federal Funds Rate
  29.     )
  30.  
  31. # Use purrr to pull all of the series from FRED
  32. data_fred <-
  33.   purrr::pmap_dfr(.l = fred_series, .f = fredr) %>%
  34.   select(date, series_id, value) %>%
  35.   pivot_wider(id_cols = "date", names_from = "series_id", values_from = "value") %>%
  36.   arrange(date)
  37.  
  38. # Filter data to the time window specified
  39. data_fred <- data_fred %>% filter(date >= date_start & date <= date_end)
  40.  
  41. # Compute the Taylor/Mankiw Rule estimates
  42. data_fred <-
  43.   data_fred %>%
  44.   mutate(Taylor_Rule = GDPDEF + 2 + 0.5 * (GDPDEF - 2) + 0.5 * ((GDPC1 - GDPPOT) / GDPPOT) * 100) %>%
  45.  
  46.   # Compute Mankiw rule using constants from Mankiw's original paper at
  47.   # http://scholar.harvard.edu/files/mankiw/files/us_monetary_policy_during_the_1990s.pdf
  48.   # mutate(Mankiw_Rule = 8.5 + 1.4 * (CPILFESL - UNRATE))
  49.  
  50.   # Compute Mankiw rule using updated constants by Lars Christensen
  51.   # at https://marketmonetarist.com/2014/09/16/mankiw-rule-tells-the-fed-to-tighten/
  52.   mutate(Mankiw_Rule = 9.1 + 2.1 * (CPILFESL - UNRATE))
  53.  
  54. ##########################################################################
  55. ### Graph: Taylor Rule, Mankiw Rule, and Fed Rate
  56. ##########################################################################
  57. c1 <- "U.S. Bureau of Economic Analysis, Real Gross Domestic Product [GDPC1]\n"
  58. c2 <- "U.S. Congressional Budget Office, Real Potential Gross Domestic Product [GDPPOT]\n"
  59. c3 <- "U.S. Bureau of Economic Analysis, Gross Domestic Product: Implicit Price Deflator [GDPDEF]\n"
  60. 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"
  61. c5 <- "U.S. Bureau of Labor Statistics, Unemployment Rate [UNRATE]\n"
  62. c6 <- "Board of Governors of the Federal Reserve System (US), Effective Federal Funds Rate [FEDFUNDS]\n"
  63. c7 <- "retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org\n"
  64. c8 <- paste("Data retrieved on", format(Sys.time(), "%B %d, %Y at %I:%M %p %Z"))
  65.  
  66. caption  <- "" #paste(c1, c2, c3, c4, c5, c6, c7, c8)
  67.  
  68. # Initialize the plot
  69. p_mankiw_taylor <-
  70.   ggplot() +
  71.   theme_bw() +
  72.   theme(legend.title = element_blank()) +
  73.   theme(legend.position = "bottom") +
  74.   # Plot the Fed Rate
  75.   geom_line(data = data_fred, size = 1.3, aes(x = date, y = FEDFUNDS/ 100, color = "Federal Funds Rate")) +
  76.  
  77.   # Plot the Taylor rule
  78.   geom_line(data = data_fred %>% filter(!is.na(Taylor_Rule)), size = 1.3, aes(x = date, y = Taylor_Rule / 100, color = "Taylor Rule")) +
  79.  
  80.   # Plot the Mankiw rule
  81.   geom_line(data = data_fred %>% filter(!is.na(Mankiw_Rule)), size = 1.3, aes(x = date, y = Mankiw_Rule / 100, color = "Mankiw Rule")) +
  82.  
  83.   geom_hline(yintercept = 0, linetype = "dotted") +
  84.  
  85.   scale_y_continuous(breaks = pretty_breaks(7), labels = scales::percent_format(accuracy = 1)) +
  86.   scale_x_date(breaks = pretty_breaks(8)) +
  87.   scale_colour_manual(values =  c("Federal Funds Rate" = "steelblue2",
  88.                                   "Taylor Rule"        = "goldenrod",
  89.                                   "Mankiw Rule"        = "red3"
  90.                                   )) +
  91.  
  92.   # Set the title, subtitle, captions, xlab, and ylab
  93.   labs(title = "Taylor Rule, Mankiw Rule, and Fed Rate",
  94.        subtitle = "Recessions marked with vertical bars",
  95.        caption = caption, x = "", y = "")
  96.  
  97. print(p_mankiw_taylor)
Add Comment
Please, Sign In to add comment