Homework 4

Author

Sophia Wang

Homework 4

Set up working environment and dataset

library("readr")
library("countrycode")
library("dplyr")

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

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library("janitor")

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

    chisq.test, fisher.test
library("tidyr")
library("ggplot2")
library("forcats")
library("scales")

Attaching package: 'scales'
The following object is masked from 'package:readr':

    col_factor
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.
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>, …
# we want to compare these two indicators
indicators_we_want <- c("Green Bond Issuances by Country", "Sovereign Green Bond Issuances")

green_debt_subset <- green_debt |> 
  # from the janitor package -- makes variables snake_case so they are easier to work with
  clean_names() |> 
  # filter for the vector of indicators we defined above
  filter(indicator %in% indicators_we_want) |> 
  # "f\\d{4}" is a regular expression (regex) that searches for all columns that are f + four digits.
  # Ask ChatGPT to explain this to you.
  select(country, iso3, indicator, matches("f\\d{4}")) 

green_debt_subset 
# A tibble: 107 × 32
   country iso3  indicator f1985 f1986 f1987 f1990 f1991 f1992 f1993 f1994 f1999
   <chr>   <chr> <chr>     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
 1 Argent… ARG   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 2 Austra… AUS   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 3 Austria AUT   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 4 Austria AUT   Sovereig…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 5 Bangla… BGD   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 6 Belaru… BLR   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 7 Belaru… BLR   Sovereig…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 8 Belgium BEL   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
 9 Belgium BEL   Sovereig…    NA    NA    NA    NA    NA    NA    NA    NA    NA
10 Bermuda BMU   Green Bo…    NA    NA    NA    NA    NA    NA    NA    NA    NA
# ℹ 97 more rows
# ℹ 20 more variables: 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>, f2021 <dbl>,
#   f2022 <dbl>

Problem 1

green_debt_subset_region <- green_debt_subset |>
  mutate(Region = countrycode(iso3, "iso3c", "region")) |>
  select(Region, everything())
green_bonds_tidy <- green_debt_subset_region |> 
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = readr::parse_number,
    values_drop_na = TRUE
  )
green_bonds_tidy
# A tibble: 465 × 6
   Region                    country   iso3  indicator      year issuance_bn_usd
   <chr>                     <chr>     <chr> <chr>         <dbl>           <dbl>
 1 Latin America & Caribbean Argentina ARG   Green Bond I…  2017          0.974 
 2 Latin America & Caribbean Argentina ARG   Green Bond I…  2020          0.0500
 3 Latin America & Caribbean Argentina ARG   Green Bond I…  2021          0.916 
 4 Latin America & Caribbean Argentina ARG   Green Bond I…  2022          0.207 
 5 East Asia & Pacific       Australia AUS   Green Bond I…  2014          0.526 
 6 East Asia & Pacific       Australia AUS   Green Bond I…  2015          0.413 
 7 East Asia & Pacific       Australia AUS   Green Bond I…  2016          0.531 
 8 East Asia & Pacific       Australia AUS   Green Bond I…  2017          2.53  
 9 East Asia & Pacific       Australia AUS   Green Bond I…  2018          2.22  
10 East Asia & Pacific       Australia AUS   Green Bond I…  2019          1.98  
# ℹ 455 more rows
green_bonds_total_cumulative <- green_bonds_tidy |> 
  group_by(Region) |> 
  summarize(total_issuance_bn_usd = sum(issuance_bn_usd)) |> 
  ungroup()

green_bonds_total_cumulative
# A tibble: 7 × 2
  Region                     total_issuance_bn_usd
  <chr>                                      <dbl>
1 East Asia & Pacific                        586. 
2 Europe & Central Asia                     1395. 
3 Latin America & Caribbean                   99.8
4 Middle East & North Africa                  10.3
5 North America                              239. 
6 South Asia                                  15.0
7 Sub-Saharan Africa                          16.2
ggplot(green_bonds_total_cumulative, 
       aes(x = reorder(Region, total_issuance_bn_usd), 
           y = total_issuance_bn_usd)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  theme_minimal() +
  scale_y_continuous(labels = scales::label_dollar(suffix = " bn"), 
                     expand = expansion(add = c(0, 0))) + 
  labs(title = "Cumulative Issuance of Green Bonds by Region",
       x = "Region",
       y = "Cumulative Issuance",
       caption = "Sophia Wang") +
  theme(plot.title = element_text(hjust = 0.5),
        legend.position = "none",  # Remove legend as fill color is now uniform
        axis.text.x = element_text(angle = 45, hjust = 1))

Problem 2

green_debt |>
  clean_names()
# A tibble: 355 × 42
   object_id 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>, …
green_debt_filtered <- green_debt |>
  filter(Type_of_Issuer!= "Not Applicable")

green_debt_filtered
# A tibble: 7 × 42
  ObjectId 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 Issuan… Bill… Refin… ECFFI    Green B…
2      348 World   <NA>  WLD   Green Bond Issuan… Bill… Refin… ECFFI    Green B…
3      349 World   <NA>  WLD   Green Bond Issuan… Bill… Refin… ECFFI    Green B…
4      350 World   <NA>  WLD   Green Bond Issuan… Bill… Refin… ECFFI    Green B…
5      351 World   <NA>  WLD   Green Bond Issuan… Bill… Refin… ECFFI    Green B…
6      352 World   <NA>  WLD   Green Bond Issuan… Bill… Refin… ECFFI    Green B…
7      353 World   <NA>  WLD   Green Bond Issuan… Bill… Refin… ECFFI    Green B…
# ℹ 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>,
#   F2016 <dbl>, F2017 <dbl>, F2018 <dbl>, F2019 <dbl>, F2020 <dbl>, …
green_debt_tidy <- green_debt_filtered |> 
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = readr::parse_number,
    values_drop_na = TRUE
  )
green_debt_tidy
# A tibble: 98 × 15
   ObjectId 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      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 3      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 4      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 5      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 6      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 7      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 8      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
 9      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
10      347 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
# ℹ 88 more rows
# ℹ 6 more variables: CTS_Full_Descriptor <chr>, Type_of_Issuer <chr>,
#   Use_of_Proceed <chr>, Principal_Currency <chr>, year <dbl>,
#   issuance_bn_usd <dbl>
green_debt_issuer <- green_debt_tidy |> 
  group_by(Type_of_Issuer) |> 
  summarize(total_issuance = sum(issuance_bn_usd)) |> 
  ungroup()

green_debt_issuer
# A tibble: 7 × 2
  Type_of_Issuer               total_issuance
  <chr>                                 <dbl>
1 Banks                                 444. 
2 International Organization            188. 
3 Local and state Government             39.3
4 Nonfinancial corporations             659. 
5 Other financial corporations          408. 
6 Sovereign                             266. 
7 State owned entities                  282. 
ggplot(green_debt_issuer, 
       aes(x = reorder(Type_of_Issuer, total_issuance ), 
           y = total_issuance )) +
  geom_bar(stat = "identity", fill = "steelblue") +
  theme_minimal() +
  scale_y_continuous(labels = scales::label_dollar(suffix = " bn"), 
                     expand = expansion(add = c(0, 0))) + 
  labs(title = "Cumulative Issuance of Green Bonds by Issuer",
       x = "Issuer",
       y = "Cumulative Issuance",
       caption = "Sophia Wang") +
  theme(plot.title = element_text(hjust = 0.5),
        legend.position = "none",  
        axis.text.x = element_text(angle = 45, hjust = 1))

banks_vs_nonfinancial_green_bonds <- green_debt_tidy |> 
  filter(Type_of_Issuer %in% c("Banks", "Nonfinancial corporations")) |> 
  group_by(year,Type_of_Issuer) |> 
  summarize(issuance_bn_usd = sum(issuance_bn_usd, na.rm = TRUE), .groups = 'drop') |>
  pivot_wider(names_from = Type_of_Issuer,
              values_from = issuance_bn_usd,
              values_fill = 0) |> 
  clean_names() 

banks_vs_nonfinancial_green_bonds
# A tibble: 21 × 3
    year  banks nonfinancial_corporations
   <dbl>  <dbl>                     <dbl>
 1  1985 0.03                       0.025
 2  1986 0.3                        0    
 3  1987 0.0751                     0    
 4  1990 0                          0    
 5  1993 0                          0.168
 6  1999 0.0482                     0    
 7  2000 0.0533                     0    
 8  2002 0.148                      0    
 9  2003 0.01                       0.172
10  2004 0.109                      0    
# ℹ 11 more rows
banks_vs_nonfinancial_green_bonds_repeatable_factoids <- banks_vs_nonfinancial_green_bonds |> 
  mutate(
    nonfinancial_corporations_x_than_banks = nonfinancial_corporations/banks,
    banks_x_than_nonfinancial_corporations = nonfinancial_corporations/banks,
    
    banks_pct_more_than_nonfinancial_corporations = (banks/nonfinancial_corporations-1) * 100,
    nonfinancial_corporations_more_than_banks = (nonfinancial_corporations/banks-1) * 100
        )

banks_vs_nonfinancial_green_bonds_repeatable_factoids
# A tibble: 21 × 7
    year  banks nonfinancial_corporations nonfinancial_corporations_x_than_banks
   <dbl>  <dbl>                     <dbl>                                  <dbl>
 1  1985 0.03                       0.025                                  0.833
 2  1986 0.3                        0                                      0    
 3  1987 0.0751                     0                                      0    
 4  1990 0                          0                                    NaN    
 5  1993 0                          0.168                                Inf    
 6  1999 0.0482                     0                                      0    
 7  2000 0.0533                     0                                      0    
 8  2002 0.148                      0                                      0    
 9  2003 0.01                       0.172                                 17.2  
10  2004 0.109                      0                                      0    
# ℹ 11 more rows
# ℹ 3 more variables: banks_x_than_nonfinancial_corporations <dbl>,
#   banks_pct_more_than_nonfinancial_corporations <dbl>,
#   nonfinancial_corporations_more_than_banks <dbl>
factoid_2022 <- banks_vs_nonfinancial_green_bonds_repeatable_factoids |> 
  filter(year == 2022) |> 
  pull(nonfinancial_corporations_x_than_banks) |> 
  round()

factoid_2022
[1] 1
factoid_2021 <- banks_vs_nonfinancial_green_bonds_repeatable_factoids |> 
  filter(year == 2021) |> 
  pull(nonfinancial_corporations_more_than_banks) |> 
  round()

factoid_2021
[1] 117

Problem 3

green_debt |> 
  clean_names() |> 
  filter(use_of_proceed != "Not Applicable")
# A tibble: 138 × 42
   object_id country iso2  iso3  indicator        unit  source cts_code cts_name
       <dbl> <chr>   <chr> <chr> <chr>            <chr> <chr>  <chr>    <chr>   
 1       209 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 2       210 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 3       211 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 4       212 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 5       213 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 6       214 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 7       215 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
 8       216 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
 9       217 World   <NA>  WLD   Cumulative Gree… Share Refin… ECFF     Green B…
10       218 World   <NA>  WLD   Cumulative Gree… Bill… Refin… ECFF     Green B…
# ℹ 128 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>, …

Use of Proceeds: This analysis reveals the primary sectors or projects financed by green bonds, such as renewable energy projects, which can indicate where investors are focusing their sustainable investment efforts.

green_debt |> 
  clean_names() |> 
  filter(principal_currency != "Not Applicable")
# A tibble: 100 × 42
   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
# ℹ 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>, …

Currency of Issuance: By examining the currency in which green bonds are issued over time, you can identify any shifts in market preferences or economic factors influencing these decisions. For instance, an increase in issuance in emerging market currencies could indicate growing interest in sustainable projects in those regions.

The echo: false option disables the printing of code (only output is displayed).