library(tidyverse) library(tidytext) library(Quandl) library(lubridate) library(glue) Quandl.api_key("Vd7t2TFEjCvipyX7zPmh")
"Broad money (M3) includes currency, deposits with an agreed maturity of up to two years, deposits redeemable at notice of up to three months and repurchase agreements, money market fund shares/units and debt securities up to two years. M3 is measured as a seasonally adjusted index based on 2015=100." "M1 includes currency i.e. banknotes and coins, plus overnight deposits. M1 is expressed as a seasonally adjusted index based on 2015=100."
country_table = glue(Sys.getenv("USERPROFILE"), "\\OneDrive - Bank Of Israel\\", "Data\\OECD\\country_codes.csv") %>% read_csv() monetary_aggregates_df = country_table %>% filter(oecd_member == 1) %>% pull(code) %>% map_dfr(function(temp_code){ # browser() broad_money = tryCatch(Quandl(glue("OECD/MEI_FIN_MABM_{temp_code}_Q"), type = "raw") %>% set_names(c("date",temp_code)) %>% mutate(category = "broad_money"), error = function(e){return(NULL)}) narrow_money = tryCatch(Quandl(glue("OECD/KEI_MANMM101_{temp_code}_ST_Q"), type = "raw") %>% set_names(c("date",temp_code)) %>% mutate(category = "narrow_money"), error = function(e){return(NULL)}) return(bind_rows(broad_money, narrow_money)) }) %>% pivot_longer(-c(date, category),names_to = "country_code") %>% filter(complete.cases(.))
monetary_aggregates_df %>% filter(date %in% c(date("2021-09-30"),date("2019-12-31"))) %>% filter(complete.cases(.)) %>% group_by(country_code, category) %>% arrange(date) %>% summarise(change = value / lag(value) - 1, .groups = "drop") %>% filter(complete.cases(.)) %>% left_join(country_table %>% select(code, country), by = c("country_code" = "code")) %>% ggplot(aes(x = change, y = reorder_within(country, change, category))) + geom_col(fill = "lightblue") + scale_y_reordered() + scale_x_continuous(labels = scales::percent_format()) + geom_text(aes(label = paste0(round(change * 100),"%")), hjust = 1) + xlab(NULL) + ylab(NULL) + facet_wrap(~category, scales = "free") + ggtitle("Percent change in monetary index (100 = 2015) 2019 Q4 - 2021 Q3")
monetary_aggregates_df %>% filter(quarter(date) == 3) %>% filter(complete.cases(.)) %>% group_by(country_code, category) %>% arrange(date) %>% summarise(change = value / lag(value) - 1, .groups = "drop") %>% filter(complete.cases(.)) %>% left_join(country_table %>% select(code, country), by = c("country_code" = "code")) %>% ggplot(aes(x = change, y = reorder_within(country, change, category))) + geom_col(fill = "lightblue") + scale_y_reordered() + scale_x_continuous(labels = scales::percent_format()) + geom_text(aes(label = paste0(round(change * 100),"%")), hjust = 1) + xlab(NULL) + ylab(NULL) + facet_wrap(~category, scales = "free") + ggtitle("Percent change in monetary index (100 = 2015) 2019 Q4 - 2021 Q3")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.