── 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 dataimf_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 needindicators_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 variablemutate(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 regiongreen_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 regionsummarise(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
# Plotggplot(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()
# 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>
# 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()
# 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_proceedgreen_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>
# 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_currencygreen_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>
# 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