W4 Deliverable, ValeriaLee

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

Setups

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.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
library(ggplot2)
library(janitor)

Attaching package: 'janitor'
The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(countrycode)

imf_climate_dashboards_green_debt_url <- "https://opendata.arcgis.com/datasets/8e2772e0b65f4e33a80183ce9583d062_0.csv"

green_debt <- imf_climate_dashboards_green_debt_url |> 
  read_csv() 
Rows: 355 Columns: 42
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (12): Country, ISO2, ISO3, Indicator, Unit, Source, CTS_Code, CTS_Name, ...
dbl (30): ObjectId, F1985, F1986, F1987, F1990, F1991, F1992, F1993, F1994, ...

ℹ 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.

Problem Set 1

green_debt
# A tibble: 355 × 42
   ObjectId Country         ISO2  ISO3  Indicator Unit  Source CTS_Code CTS_Name
      <dbl> <chr>           <chr> <chr> <chr>     <chr> <chr>  <chr>    <chr>   
 1        1 Argentina       AR    ARG   Green Bo… Bill… Refin… ECFFI    Green B…
 2        2 Australia       AU    AUS   Green Bo… Bill… Refin… ECFFI    Green B…
 3        3 Austria         AT    AUT   Green Bo… Bill… Refin… ECFFI    Green B…
 4        4 Austria         AT    AUT   Sovereig… Bill… Refin… ECFF     Green B…
 5        5 Bangladesh      BD    BGD   Green Bo… Bill… Refin… ECFFI    Green B…
 6        6 Belarus, Rep. … BY    BLR   Green Bo… Bill… Refin… ECFFI    Green B…
 7        7 Belarus, Rep. … BY    BLR   Sovereig… Bill… Refin… ECFF     Green B…
 8        8 Belgium         BE    BEL   Green Bo… Bill… Refin… ECFFI    Green B…
 9        9 Belgium         BE    BEL   Sovereig… Bill… Refin… ECFF     Green B…
10       10 Bermuda         BM    BMU   Green Bo… Bill… Refin… ECFFI    Green B…
# ℹ 345 more rows
# ℹ 33 more variables: CTS_Full_Descriptor <chr>, Type_of_Issuer <chr>,
#   Use_of_Proceed <chr>, Principal_Currency <chr>, F1985 <dbl>, F1986 <dbl>,
#   F1987 <dbl>, F1990 <dbl>, F1991 <dbl>, F1992 <dbl>, F1993 <dbl>,
#   F1994 <dbl>, F1999 <dbl>, F2000 <dbl>, F2002 <dbl>, F2003 <dbl>,
#   F2004 <dbl>, F2007 <dbl>, F2008 <dbl>, F2009 <dbl>, F2010 <dbl>,
#   F2011 <dbl>, F2012 <dbl>, F2013 <dbl>, F2014 <dbl>, F2015 <dbl>, …
indicators_we_want <- c("Green Bond Issuances by Country", "Sovereign Green Bond Issuances")

green_debt_subset <- green_debt |>
clean_names() |> 
  filter(indicator %in% indicators_we_want) |> 
  select(country, iso3, indicator, matches("f\\d{4}")) 

green_debt_subset |> 
  pivot_longer(
    cols = matches("f\\d{4}")
  )
# A tibble: 3,103 × 5
   country   iso3  indicator                       name  value
   <chr>     <chr> <chr>                           <chr> <dbl>
 1 Argentina ARG   Green Bond Issuances by Country f1985    NA
 2 Argentina ARG   Green Bond Issuances by Country f1986    NA
 3 Argentina ARG   Green Bond Issuances by Country f1987    NA
 4 Argentina ARG   Green Bond Issuances by Country f1990    NA
 5 Argentina ARG   Green Bond Issuances by Country f1991    NA
 6 Argentina ARG   Green Bond Issuances by Country f1992    NA
 7 Argentina ARG   Green Bond Issuances by Country f1993    NA
 8 Argentina ARG   Green Bond Issuances by Country f1994    NA
 9 Argentina ARG   Green Bond Issuances by Country f1999    NA
10 Argentina ARG   Green Bond Issuances by Country f2000    NA
# ℹ 3,093 more rows

Cumulative Issuance by Region

green_debt$region <- countrycode(green_debt$Country, 'country.name', 'region')
Warning: Some values were not matched unambiguously: World
cumulative_issuance_by_region <- green_debt %>%
  filter(!is.na(region)) %>%
  group_by(region) %>%
  summarize(cumulative_issuance = sum(across(starts_with('F')), na.rm = TRUE))

ggplot(cumulative_issuance_by_region, aes(x = reorder(region, -cumulative_issuance), y = cumulative_issuance)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  scale_color_brewer(palette = "Set3") +
  labs(title = "Cumulative Issuance of Green Bonds by Region", x = "Region", y = "Cumulative Issuance") +
  theme(axis.text.x = element_text(hjust = 0.75, vjust = 0.75), plot.title = element_text(hjust = 0.5)) +
  coord_flip()

Practice Question 2

Filter out observations where type_of_issuer is “Not Applicable”

green_debt <- green_debt %>%
  janitor::clean_names()

green_debt_clean <- green_debt %>%
  filter(type_of_issuer != "Not Applicable")

green_debt_clean
# A tibble: 7 × 43
  object_id country iso2  iso3  indicator         unit  source cts_code cts_name
      <dbl> <chr>   <chr> <chr> <chr>             <chr> <chr>  <chr>    <chr>   
1       347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
2       348 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
3       349 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
4       350 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
5       351 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
6       352 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
7       353 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
# ℹ 34 more variables: cts_full_descriptor <chr>, type_of_issuer <chr>,
#   use_of_proceed <chr>, principal_currency <chr>, f1985 <dbl>, f1986 <dbl>,
#   f1987 <dbl>, f1990 <dbl>, f1991 <dbl>, f1992 <dbl>, f1993 <dbl>,
#   f1994 <dbl>, f1999 <dbl>, f2000 <dbl>, f2002 <dbl>, f2003 <dbl>,
#   f2004 <dbl>, f2007 <dbl>, f2008 <dbl>, f2009 <dbl>, f2010 <dbl>,
#   f2011 <dbl>, f2012 <dbl>, f2013 <dbl>, f2014 <dbl>, f2015 <dbl>,
#   f2016 <dbl>, f2017 <dbl>, f2018 <dbl>, f2019 <dbl>, f2020 <dbl>, …
green_debt_cumulative <- green_debt_clean %>%
  pivot_longer(
    cols = starts_with("f"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = list(year = as.integer),
    values_drop_na = TRUE
  ) %>% 
  group_by(type_of_issuer) %>% 
  mutate(green_debt_cumulative = cumsum(issuance_bn_usd))
Warning in f(names[[col]]): NAs introduced by coercion
ggplot(green_debt_cumulative, 
       aes(x = factor(1), 
           y = green_debt_cumulative, 
           fill = type_of_issuer)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  coord_polar(theta = "y") +
  scale_fill_brewer(palette = "Set3") +
  scale_y_continuous(labels = scales::label_dollar(suffix = " bn"),
                     expand = c(0, 0)) +
  labs(title = "Distribution of Cumulative Green Debt Issuance by Issuer",
       x = NULL,
       y = NULL,
       fill = "Issuer",
       caption = "ValeriaLee")

Practice Question 3

Proceeds For:

green_debt |> 
  clean_names() |> 
  filter(type_of_issuer != "Not Applicable")
# A tibble: 7 × 43
  object_id country iso2  iso3  indicator         unit  source cts_code cts_name
      <dbl> <chr>   <chr> <chr> <chr>             <chr> <chr>  <chr>    <chr>   
1       347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
2       348 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
3       349 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
4       350 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
5       351 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
6       352 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
7       353 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
# ℹ 34 more variables: cts_full_descriptor <chr>, type_of_issuer <chr>,
#   use_of_proceed <chr>, principal_currency <chr>, f1985 <dbl>, f1986 <dbl>,
#   f1987 <dbl>, f1990 <dbl>, f1991 <dbl>, f1992 <dbl>, f1993 <dbl>,
#   f1994 <dbl>, f1999 <dbl>, f2000 <dbl>, f2002 <dbl>, f2003 <dbl>,
#   f2004 <dbl>, f2007 <dbl>, f2008 <dbl>, f2009 <dbl>, f2010 <dbl>,
#   f2011 <dbl>, f2012 <dbl>, f2013 <dbl>, f2014 <dbl>, f2015 <dbl>,
#   f2016 <dbl>, f2017 <dbl>, f2018 <dbl>, f2019 <dbl>, f2020 <dbl>, …
green_debt %>%
  distinct(use_of_proceed)
# A tibble: 70 × 1
   use_of_proceed                        
   <chr>                                 
 1 Not Applicable                        
 2 Access to Essential Services          
 3 Acquiring and distribution of vaccine 
 4 Acquisition                           
 5 Affordable Basic Infrastructure       
 6 Agriculture                           
 7 Alternative Energy                    
 8 Aquatic Biodiversity Conservation     
 9 Capital expenditure                   
10 Capital expenditure/Financing expenses
# ℹ 60 more rows

What do we know about the currency of issuance?

green_debt_principals <- green_debt %>%
  clean_names() %>%
  filter(principal_currency != "Not Applicable")

principal_currency <- green_debt_principals %>% 
  pivot_longer(
    cols = starts_with("f"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = readr::parse_number
  ) |> 
  arrange(principal_currency, year) %>% 
  group_by(principal_currency, year) %>% 
  mutate(cumulative_bn_usd = cumsum(issuance_bn_usd)) %>%
  filter(!is.na(cumulative_bn_usd)) 

principal_currency
# A tibble: 100 × 17
# Groups:   principal_currency, year [50]
   object_id country iso2  iso3  indicator        unit  source cts_code cts_name
       <dbl> <chr>   <chr> <chr> <chr>            <chr> <chr>  <chr>    <chr>   
 1       109 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 2       110 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 3       111 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 4       112 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 5       113 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 6       114 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 7       115 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 8       116 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 9       117 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
10       118 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
# ℹ 90 more rows
# ℹ 8 more variables: cts_full_descriptor <chr>, type_of_issuer <chr>,
#   use_of_proceed <chr>, principal_currency <chr>, region <chr>, year <dbl>,
#   issuance_bn_usd <dbl>, cumulative_bn_usd <dbl>
top_10_principal_currency <- principal_currency |> 
  group_by(principal_currency) |> 
  slice_max(order_by = year) |> 
  arrange(desc(cumulative_bn_usd)) |> 
  select(principal_currency, cumulative_bn_usd) |> 
  ungroup() |> 
  slice_max(order_by = cumulative_bn_usd, n = 10) |> 
  ggplot(aes(x = cumulative_bn_usd, 
             y = fct_reorder(principal_currency, cumulative_bn_usd),
             fill = principal_currency)) +
  geom_col() +
  scale_fill_brewer(palette = "Set3") +
  labs(title = "Top 10 Green Bond Principal Currencies",
       x = "Cumulative Issuance",
       y = "Principal Currency",
       caption = "ValeriaLee") +
  theme_minimal()

top_10_principal_currency

Is that changing over time?

green_debt_over_time <- green_debt %>%
  pivot_longer(
    cols = starts_with("f"),  
    names_to = "year",  
    names_prefix = "f",  
    values_to = "value"  
  ) %>%
  mutate(year = as.integer(year)) %>%
  group_by(year) %>%
  summarise(total_issuance = n())

ggplot(green_debt_over_time, aes(x = year, y = total_issuance)) +
  geom_line() +
  geom_smooth(method = "lm", se = FALSE) +  
  labs(title = "Green Debt Issuance Trending Over Time",
       x = "Year",
       y = "Total Issuance") +
  theme_minimal()
`geom_smooth()` using formula = 'y ~ x'