Quarto 4

Author

Haotian Duan

3.5.0.1 Homework problem 1

# Use the package
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ 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(janitor)

Attaching package: 'janitor'

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

    chisq.test, fisher.test
library(countrycode)
library(ggplot2)
# Import the data
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.
# Select the column we need
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}")) |>
# Use the countrycode package to add the region as a variable
  mutate(region = countrycode(iso3, "iso3c", "region"))
green_debt_subset
# A tibble: 107 × 33
   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
# ℹ 21 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>, region <chr>
# Group by region
green_bonds_tidy_cumulative_region <- green_debt_subset |> 
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = readr::parse_number,
    values_drop_na = TRUE
  ) |>
  select(-iso3) |> 
  filter(indicator == "Green Bond Issuances by Country") |> 
  group_by(region) |> 
# Calculate the cumulative issuance of green bonds by region
  summarise(cumulative_bn_usd = sum(issuance_bn_usd)) |>
  arrange(cumulative_bn_usd|> desc())
green_bonds_tidy_cumulative_region
# A tibble: 7 × 2
  region                     cumulative_bn_usd
  <chr>                                  <dbl>
1 Europe & Central Asia                1161.  
2 East Asia & Pacific                   567.  
3 North America                         236.  
4 Latin America & Caribbean              92.1 
5 Sub-Saharan Africa                     16.1 
6 South Asia                             15.0 
7 Middle East & North Africa              8.85
# Plot
ggplot(green_bonds_tidy_cumulative_region) +
  aes(x = reorder(region, -cumulative_bn_usd), y = cumulative_bn_usd) +
  geom_col(fill = "red") +
  coord_flip()+
  labs(
    x = "Region",
    y = "Cumulative Issuance of Green Bonds",
    title = "Cumulative Issuance of Green Bonds by Region",
    caption = "Haotian Duan"
  ) +
  theme_minimal()

3.5.0.2 Homework problem 2:

green_bonds_tidy_1 <- green_debt |> 
  clean_names() |> 
  filter(type_of_issuer != "Not Applicable") |>
  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_1
# A tibble: 98 × 15
   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 Issu… Bill… Refin… ECFFI    Green B…
 2       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 3       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 4       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 5       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 6       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 7       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 8       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
 9       347 World   <NA>  WLD   Green Bond Issu… Bill… Refin… ECFFI    Green B…
10       347 World   <NA>  WLD   Green Bond Issu… 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_bonds_tidy_cumulative_1 <- green_bonds_tidy_1 |>
  select(-iso3) |> 
  arrange(type_of_issuer, year) |> 
  group_by(type_of_issuer, indicator) |> 
  mutate(cumulative_bn_usd = cumsum(issuance_bn_usd)) |> 
  ungroup() |>
  group_by(type_of_issuer) |> 
  slice_max(order_by = year) |> 
  arrange(cumulative_bn_usd|> desc()) |> 
  select(type_of_issuer, cumulative_bn_usd) |> 
  ungroup() |>
  slice_max(order_by = cumulative_bn_usd, n = 10)
green_bonds_tidy_cumulative_1
# A tibble: 7 × 2
  type_of_issuer               cumulative_bn_usd
  <chr>                                    <dbl>
1 Nonfinancial corporations                659. 
2 Banks                                    444. 
3 Other financial corporations             408. 
4 State owned entities                     282. 
5 Sovereign                                266. 
6 International Organization               188. 
7 Local and state Government                39.3
ggplot(green_bonds_tidy_cumulative_1) +
  aes(x = type_of_issuer, y = cumulative_bn_usd) +
  geom_col(fill = "yellow") +
  labs(
    x = "Type of Issuer",
    y = "Cumulative Issuance",
    title = "Top 10 Type of Issuer",
    caption = "Haotian Duan"
  ) +
  coord_flip() +
  theme_minimal()

green_bonds_by_type_of_issuer_factoids <- green_bonds_tidy_1 |> 
  select(-iso3) |> 
  pivot_wider(names_from = type_of_issuer,
              values_from = issuance_bn_usd,
              
              values_fill = 0) |>
  clean_names() |>
  mutate(
    nonfinancial_corporations_x_than_banks = nonfinancial_corporations/banks,
    banks_x_than_nonfinancial_corporations = banks/nonfinancial_corporations,
    nonfinancial_corporationst_pct_more_than_banks = (nonfinancial_corporations/banks-1) * 100,
    banks_pct_more_than_nonfinancial_corporationst = (banks/nonfinancial_corporations-1) *100
  )
green_bonds_by_type_of_issuer_factoids
# A tibble: 98 × 23
   object_id country iso2  indicator              unit  source cts_code cts_name
       <dbl> <chr>   <chr> <chr>                  <chr> <chr>  <chr>    <chr>   
 1       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 2       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 3       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 4       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 5       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 6       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 7       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 8       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
 9       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
10       347 World   <NA>  Green Bond Issuances … Bill… Refin… ECFFI    Green B…
# ℹ 88 more rows
# ℹ 15 more variables: cts_full_descriptor <chr>, use_of_proceed <chr>,
#   principal_currency <chr>, year <dbl>, banks <dbl>,
#   international_organization <dbl>, local_and_state_government <dbl>,
#   nonfinancial_corporations <dbl>, other_financial_corporations <dbl>,
#   sovereign <dbl>, state_owned_entities <dbl>,
#   nonfinancial_corporations_x_than_banks <dbl>, …

3.5.0.3 Homework problem 3

# Repeat the process from problem 2 for use_of_proceed
green_bonds_tidy_2 <- green_debt |> 
  clean_names() |> 
  filter(use_of_proceed != "Not Applicable") |>
  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_2
# A tibble: 138 × 15
   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
# ℹ 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_bonds_tidy_cumulative_2 <- green_bonds_tidy_2 |>
  select(-iso3) |> 
  arrange(use_of_proceed, year) |> 
  group_by(use_of_proceed, indicator) |> 
  mutate(cumulative_bn_usd = cumsum(issuance_bn_usd)) |> 
  ungroup() |>
  group_by(use_of_proceed) |> 
  slice_max(order_by = year) |> 
  arrange(cumulative_bn_usd|> desc()) |> 
  select(use_of_proceed, cumulative_bn_usd) |> 
  ungroup() |>
  slice_max(order_by = cumulative_bn_usd, n = 10)
green_bonds_tidy_cumulative_2
# A tibble: 10 × 2
   use_of_proceed                                              cumulative_bn_usd
   <chr>                                                                   <dbl>
 1 Clean Transport                                                         834. 
 2 Energy Efficiency                                                       480. 
 3 Climate Change Adaptation                                               277. 
 4 Eligible Green Projects                                                 204. 
 5 Green Construction/Buildings                                            127. 
 6 Renewable Energy Projects                                               108. 
 7 Aquatic Biodiversity Conservation                                        75.7
 8 Circular Economy Adapted/Eco-efficient Products, Productio…              33.6
 9 Alternative Energy                                                       25.7
10 Sustainable Water or Wastewater management                               17.7
ggplot(green_bonds_tidy_cumulative_2) +
  aes(x = use_of_proceed, y = cumulative_bn_usd) +
  geom_col(fill = "blue") +
  labs(
    x = "Use of Proceed",
    y = "Cumulative Issuance",
    title = "Top 10 Use of proceed",
    caption = "Haotian Duan"
  ) +
  coord_flip() +
  theme_minimal()

green_bonds_by_use_of_proceed_factoids <- green_bonds_tidy_2 |> 
  select(-iso3) |> 
  pivot_wider(names_from = use_of_proceed,
              values_from = issuance_bn_usd,
              
              values_fill = 0) |>
  clean_names() |>
  mutate(
    clean_transport_x_than_energy_efficiency = clean_transport/energy_efficiency,
    energy_efficiency_x_than_clean_transport = energy_efficiency/clean_transport,
    clean_transport_pct_more_than_energy_efficiency = (clean_transport/energy_efficiency-1) * 100,
    energy_efficiency_pct_more_than_clean_transport = (energy_efficiency/clean_transport-1) *100
  )
green_bonds_by_use_of_proceed_factoids
# A tibble: 138 × 85
   object_id country iso2  indicator              unit  source cts_code cts_name
       <dbl> <chr>   <chr> <chr>                  <chr> <chr>  <chr>    <chr>   
 1       209 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 2       210 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 3       211 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 4       212 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 5       213 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 6       214 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 7       215 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 8       216 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 9       217 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
10       218 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
# ℹ 128 more rows
# ℹ 77 more variables: cts_full_descriptor <chr>, type_of_issuer <chr>,
#   principal_currency <chr>, year <dbl>, access_to_essential_services <dbl>,
#   acquiring_and_distribution_of_vaccine <dbl>, acquisition <dbl>,
#   affordable_basic_infrastructure <dbl>, agriculture <dbl>,
#   alternative_energy <dbl>, aquatic_biodiversity_conservation <dbl>,
#   capital_expenditure <dbl>, capital_expenditure_financing_expenses <dbl>, …
# Repeat the process from problem 2 for principal_currency
green_bonds_tidy_3 <- green_debt |> 
  clean_names() |> 
  filter(principal_currency != "Not Applicable") |>
  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_3
# A tibble: 100 × 15
   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
# ℹ 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_bonds_tidy_cumulative_3 <- green_bonds_tidy_3 |>
  select(-iso3) |> 
  arrange(principal_currency, year) |> 
  group_by(principal_currency, indicator) |> 
  mutate(cumulative_bn_usd = cumsum(issuance_bn_usd)) |> 
  ungroup() |>
  group_by(principal_currency) |> 
  slice_max(order_by = year) |> 
  arrange(cumulative_bn_usd|> desc()) |> 
  select(principal_currency, cumulative_bn_usd) |> 
  ungroup() |>
  slice_max(order_by = cumulative_bn_usd, n = 10)
green_bonds_tidy_cumulative_3
# A tibble: 10 × 2
   principal_currency cumulative_bn_usd
   <chr>                          <dbl>
 1 Euro                           977. 
 2 US Dollar                      580. 
 3 Chinese Yuan                   326. 
 4 Swedish Krona                   73.3
 5 British Pound                   73.3
 6 Canadian Dollar                 53.1
 7 Japanese Yen                    33.8
 8 Australian Dollar               27.8
 9 Swiss Franc                     22.4
10 Danish Krone                    20.3
ggplot(green_bonds_tidy_cumulative_3) +
  aes(x = principal_currency, y = cumulative_bn_usd) +
  geom_col(fill = "green") +
  labs(
    x = "Principal Currency",
    y = "Cumulative Issuance",
    title = "Top 10 Principal Currency",
    caption = "Haotian Duan"
  ) +
  coord_flip() +
  theme_minimal()

green_bonds_by_principal_currency_factoids <- green_bonds_tidy_3 |> 
  select(-iso3) |> 
  pivot_wider(names_from = principal_currency,
              values_from = issuance_bn_usd,
              
              values_fill = 0) |>
  clean_names() |>
  mutate(
    euro_x_than_us_dollar = euro/us_dollar,
    energy_efficiency_x_than_clean_transport = us_dollar/euro,
    clean_transport_pct_more_than_energy_efficiency = (euro/us_dollar-1) * 100,
    energy_efficiency_pct_more_than_clean_transport = (us_dollar/euro-1) *100
  )
green_bonds_by_principal_currency_factoids
# A tibble: 100 × 66
   object_id country iso2  indicator              unit  source cts_code cts_name
       <dbl> <chr>   <chr> <chr>                  <chr> <chr>  <chr>    <chr>   
 1       109 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 2       110 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 3       111 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 4       112 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 5       113 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 6       114 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 7       115 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
 8       116 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
 9       117 World   <NA>  Cumulative Green Bond… Share Refin… ECFF     Green B…
10       118 World   <NA>  Cumulative Green Bond… Bill… Refin… ECFF     Green B…
# ℹ 90 more rows
# ℹ 58 more variables: cts_full_descriptor <chr>, type_of_issuer <chr>,
#   use_of_proceed <chr>, year <dbl>, argentinian_peso <dbl>,
#   argentinian_unidades_de_valor_adquisitivo <dbl>, australian_dollar <dbl>,
#   bangladeshi_taka <dbl>, brazilian_real <dbl>, british_pound <dbl>,
#   canadian_dollar <dbl>, chilean_peso <dbl>, chilean_unidad_de_fomento <dbl>,
#   chinese_yuan <dbl>, colombian_peso <dbl>, czech_koruna <dbl>, …