knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(tidyverse)

library(lubridate)

library(Quandl)

library(MiscImport)

library(ggrepel)
Quandl.api_key("Vd7t2TFEjCvipyX7zPmh")

inf_df = Quandl("ODA/ISR_PCPIEPCH")

inf_df = inf_df %>% 
  rename_all(tolower) %>% 
  mutate(year = year(date)) %>% 
  select(-date)
cpi_df = import_bis_cpi_index(
  paste0(
    file.path(Sys.getenv("USERPROFILE")),
    "\\OneDrive - Bank Of Israel\\Data",
    "\\BIS\\WEBSTATS_LONG_CPI_DATAFLOW_csv_col.csv"
  ),my_frequency = "Annual",my_unit_of_measure = "Index, 2010 = 100",
  pivot_to_long = TRUE) %>% 
  filter(country == "Israel") %>% 
  filter(complete.cases(.)) %>% 
  rename(year = date)

inf_df = cpi_df %>% 
  mutate(inf = (cpi / lag(cpi) - 1) * 100) %>% 
  select(-cpi,-country, year) %>% 
  filter(complete.cases(.))

target_inf_df = read_csv(paste0(
  file.path(Sys.getenv("USERPROFILE")),
  "\\Documents\\",
  "Israel\\data\\inf-target_df.csv"),
  col_types = "cdd")

Inflation before the stabilization plan

inf_df %>% 
  filter(year <= 1970) %>% 
  ggplot(aes(x = year, y = inf)) + 
  geom_col() + 
  xlab(NULL) + ylab(NULL) + 
  theme(axis.text.x = element_text(angle = 90))

cpi_df %>% 
  filter(country == "Israel") %>% 
  filter(year <= 1970) %>% 
  mutate(cpi = cpi / cpi[1]) %>% 
  ggplot(aes(x = year, y = cpi, group = 1)) + 
  geom_line() + 
  geom_text_repel(aes(label = ifelse(cpi == max(cpi),round(cpi,2),""))) + 
  xlab(NULL) + ylab(NULL) + 
  theme(axis.text.x = element_text(angle = 90))
inf_df %>% 
  filter(year > 1970 & year <= 1985) %>% 
  ggplot(aes(x = year, y = inf)) + 
  geom_col() + 
  xlab(NULL) + ylab(NULL) + 
  theme(axis.text.x = element_text(angle = 90))

cpi_df %>% 
  filter(country == "Israel") %>% 
  filter(year <= 1980) %>% 
  mutate(cpi = cpi / cpi[1]) %>% 
  ggplot(aes(x = year, y = cpi, group = 1)) + 
  geom_line() + 
  geom_text_repel(aes(label = ifelse(cpi == max(cpi),round(cpi,2),""))) + 
  xlab(NULL) + ylab(NULL) + 
  theme(axis.text.x = element_text(angle = 90))
inf_df %>% 
  filter(year > 1980 & year <= 1985) %>% 
  ggplot(aes(x = year, y = inf)) + 
  geom_col() + 
  xlab(NULL) + ylab(NULL) + 
  theme(axis.text.x = element_text(angle = 90))

cpi_df %>% 
  filter(country == "Israel") %>% 
  filter(year > 1980 & year <= 1985) %>% 
  mutate(cpi = cpi / cpi[1]) %>% 
  ggplot(aes(x = year, y = cpi, group = 1)) + 
  geom_line() + 
  geom_text_repel(aes(label = ifelse(cpi == max(cpi),round(cpi,2),""))) + 
  xlab(NULL) + ylab(NULL) + 
  theme(axis.text.x = element_text(angle = 90))

Inflation rates plot

inf_df %>% 
  # filter(year >= 1986) %>% 
  ggplot(aes(x = year, y = inf, fill = (inf <= 0))) + 
  geom_bar(stat = "identity", width = 0.5) +
  labs(title = "Inflation rates in Israel", x = "", y = "") +
  scale_y_continuous(labels = scales::percent_format(
    scale = 1,accuracy = 3)) +
  scale_fill_manual(values = c("darkblue","red")) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5,
                                  family = "serif", size = 15),
        axis.text.x = element_text(angle = 90, vjust = 0.5))
inf_df %>% 
  filter(year >= 1992) %>% 
  left_join(target_inf_df, by = "year") %>% 
  mutate(in_range = (inf >= target_low & inf <= target_high)) %>% 
  ggplot(aes(x = as.character(year), y = inf, color = in_range)) + 
  geom_errorbar(aes(x = as.character(year),ymin = target_low,
                    ymax = target_high), color = "lightblue", size = 1) + 
  geom_point(show.legend = FALSE, size = 2) +
  labs(title = "Inflation targeting in Israel", x = "", y = "") +
  scale_y_continuous(labels = scales::percent_format(
    scale = 1,accuracy = 3)) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5,
                                  family = "serif", size = 15),
        axis.text.x = element_text(angle = 90, vjust = 0.5))


MichaelGurkov/LearningMaterials documentation built on July 9, 2022, 5:17 p.m.