My Forth Quarto Document

Author

Yin Guan

Problem 1

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)
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>
green_debt_subset$region <- countrycode(green_debt_subset$iso3, "iso3c", "region")
green_debt_by_region <- green_debt_subset  %>%
  group_by(region) %>%
  summarise(across(where(is.numeric), sum, na.rm = TRUE)) %>%
  mutate(cumulative_issuance = rowSums(select(., where(is.numeric)), na.rm = TRUE))
Warning: There was 1 warning in `summarise()`.
ℹ In argument: `across(where(is.numeric), sum, na.rm = TRUE)`.
ℹ In group 1: `region = "East Asia & Pacific"`.
Caused by warning:
! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
Supply arguments directly to `.fns` through an anonymous function instead.

  # Previously
  across(a:b, mean, na.rm = TRUE)

  # Now
  across(a:b, \(x) mean(x, na.rm = TRUE))
green_debt_by_region
# A tibble: 7 × 31
  region   f1985 f1986  f1987 f1990  f1991 f1992 f1993 f1994  f1999  f2000 f2002
  <chr>    <dbl> <dbl>  <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl> <dbl>
1 East As… 0       0   0          0 0      0     0     0     0      0      0    
2 Europe … 0.03    0.3 0.0751     0 0.0292 0.144 0.186 0.110 0.0482 0.0533 0.148
3 Latin A… 0       0   0          0 0      0     0     0     0      0      0    
4 Middle … 0       0   0          0 0      0     0     0     0      0      0    
5 North A… 0.025   0   0          0 0      0     0     0     0      0      0    
6 South A… 0       0   0          0 0      0     0     0     0      0      0    
7 Sub-Sah… 0       0   0          0 0      0     0     0     0      0      0    
# ℹ 19 more variables: 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>,
#   cumulative_issuance <dbl>
ggplot(green_debt_by_region) +
  aes(x = region, y = cumulative_issuance) +
  geom_col(fill = "#112446") +
  labs(
    x = "Regions",
    y = "Issuance",
    title = "Cumulative issuance by regions",
    caption = "Yin Guan"
  ) +
  theme_minimal()

Problem 2

green_debt_filtered_summarized_TOI <- green_debt |>
  clean_names() %>%
  mutate(issuance_value = rowSums(select(., matches("f\\d{4}")), na.rm = TRUE)) %>%
  filter(type_of_issuer != "Not Applicable") %>%
  group_by(type_of_issuer) %>%
  summarise(total_issuance = sum(issuance_value, na.rm = TRUE)) 
green_debt_filtered_summarized_TOI
# 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_filtered_summarized_TOI, aes(x=reorder(type_of_issuer, total_issuance), y=total_issuance, fill=type_of_issuer)) +
  geom_bar(stat="identity") +
  theme_minimal() +
  labs(title="Total Green Bond Issuances by Issuer Type", x="Issuer Type", y="Total Issuance") +
  coord_flip()

total_issuance_sum_TOI <- sum(green_debt_filtered_summarized_TOI$total_issuance)

green_debt_filtered_summarized_TOI %>%
  mutate(percentage_of_total = (total_issuance / total_issuance_sum_TOI) * 100)
# A tibble: 7 × 3
  type_of_issuer               total_issuance percentage_of_total
  <chr>                                 <dbl>               <dbl>
1 Banks                                 444.                19.4 
2 International Organization            188.                 8.21
3 Local and state Government             39.3                1.72
4 Nonfinancial corporations             659.                28.9 
5 Other financial corporations          408.                17.8 
6 Sovereign                             266.                11.6 
7 State owned entities                  282.                12.3 
max_issuer_TOI <- green_debt_filtered_summarized_TOI %>%
  filter(total_issuance == max(total_issuance))

min_issuer_TOI <- green_debt_filtered_summarized_TOI %>%
  filter(total_issuance == min(total_issuance))

multiple_TOI <- max_issuer_TOI$total_issuance / min_issuer_TOI$total_issuance

multiple_TOI
[1] 16.77114

Problem 3

#Use of Proceed
green_debt_filtered_summarized_UOP <- green_debt |>
  clean_names() %>%
  mutate(issuance_value = rowSums(select(., matches("f\\d{4}")), na.rm = TRUE)) %>%
  filter(use_of_proceed != "Not Applicable") %>%
  group_by(use_of_proceed) %>%
  summarise(total_issuance = sum(issuance_value, na.rm = TRUE)) 
green_debt_filtered_summarized_UOP
# A tibble: 69 × 2
   use_of_proceed                                                 total_issuance
   <chr>                                                                   <dbl>
 1 Access to Essential Services                                          12.8   
 2 Acquiring and distribution of vaccine                                  0.400 
 3 Acquisition                                                            7.40  
 4 Affordable Basic Infrastructure                                        0.0428
 5 Agriculture                                                            0.503 
 6 Alternative Energy                                                    25.7   
 7 Aquatic Biodiversity Conservation                                     75.7   
 8 Capital expenditure                                                    1.50  
 9 Capital expenditure/Financing expenses                                 1.81  
10 Carbon reduction through reforestation and avoided deforestat…         4.98  
# ℹ 59 more rows
ggplot(green_debt_filtered_summarized_UOP, aes(x=reorder(use_of_proceed, total_issuance), y=total_issuance, fill=use_of_proceed)) +
  geom_bar(stat="identity") +
  theme_minimal() +
  labs(title="Total Green Bond Issuances by Use of Proceed", x="Use of Proceed", y="Total Issuance") +
  coord_flip()

total_issuance_sum_UOP <- sum(green_debt_filtered_summarized_UOP$total_issuance)

green_debt_filtered_summarized_UOP %>%
  mutate(percentage_of_total = (total_issuance / total_issuance_sum_UOP) * 100)
# A tibble: 69 × 3
   use_of_proceed                             total_issuance percentage_of_total
   <chr>                                               <dbl>               <dbl>
 1 Access to Essential Services                      12.8                0.562  
 2 Acquiring and distribution of vaccine              0.400              0.0175 
 3 Acquisition                                        7.40               0.324  
 4 Affordable Basic Infrastructure                    0.0428             0.00188
 5 Agriculture                                        0.503              0.0220 
 6 Alternative Energy                                25.7                1.13   
 7 Aquatic Biodiversity Conservation                 75.7                3.32   
 8 Capital expenditure                                1.50               0.0658 
 9 Capital expenditure/Financing expenses             1.81               0.0795 
10 Carbon reduction through reforestation an…         4.98               0.218  
# ℹ 59 more rows
max_issuer_UOP <- green_debt_filtered_summarized_UOP %>%
  filter(total_issuance == max(total_issuance))

min_issuer_UOP <- green_debt_filtered_summarized_UOP %>%
  filter(total_issuance == min(total_issuance))

multiple_UOP <- max_issuer_UOP$total_issuance / min_issuer_UOP$total_issuance

multiple_UOP
[1] 3342934
#Principle Currency
green_debt_filtered_summarized_PC <- green_debt |>
  clean_names() %>%
  mutate(issuance_value = rowSums(select(., matches("f\\d{4}")), na.rm = TRUE)) %>%
  filter(principal_currency != "Not Applicable") %>%
  group_by(principal_currency) %>%
  summarise(total_issuance = sum(issuance_value, na.rm = TRUE)) 
green_debt_filtered_summarized_PC
# A tibble: 50 × 2
   principal_currency                        total_issuance
   <chr>                                              <dbl>
 1 Argentinian Peso                                  0.0240
 2 Argentinian Unidades de Valor Adquisitivo         0     
 3 Australian Dollar                                27.8   
 4 Bangladeshi Taka                                  0.387 
 5 Brazilian Real                                    4.89  
 6 British Pound                                    73.3   
 7 Canadian Dollar                                  53.1   
 8 Chilean Peso                                      0.0311
 9 Chilean Unidad de Fomento                         0.215 
10 Chinese Yuan                                    326.    
# ℹ 40 more rows
ggplot(green_debt_filtered_summarized_PC, aes(x=reorder(principal_currency, total_issuance), y=total_issuance, fill=principal_currency)) +
  geom_bar(stat="identity") +
  theme_minimal() +
  labs(title="Total Green Bond Issuances by Use of Proceed", x="Use of Proceed", y="Total Issuance") +
  coord_flip()

total_issuance_sum_PC <- sum(green_debt_filtered_summarized_PC$total_issuance)

 green_debt_filtered_summarized_PC %>%
  mutate(percentage_of_total = (total_issuance / total_issuance_sum_PC) * 100)
# A tibble: 50 × 3
   principal_currency                        total_issuance percentage_of_total
   <chr>                                              <dbl>               <dbl>
 1 Argentinian Peso                                  0.0240             0.00105
 2 Argentinian Unidades de Valor Adquisitivo         0                  0      
 3 Australian Dollar                                27.8                1.22   
 4 Bangladeshi Taka                                  0.387              0.0169 
 5 Brazilian Real                                    4.89               0.214  
 6 British Pound                                    73.3                3.21   
 7 Canadian Dollar                                  53.1                2.32   
 8 Chilean Peso                                      0.0311             0.00136
 9 Chilean Unidad de Fomento                         0.215              0.00939
10 Chinese Yuan                                    326.                14.2    
# ℹ 40 more rows
max_issuer_PC <- green_debt_filtered_summarized_PC %>%
  filter(total_issuance == max(total_issuance))

min_issuer_PC <- green_debt_filtered_summarized_PC %>%
  filter(total_issuance == min(total_issuance))

multiple_PC <- max_issuer_PC$total_issuance / min_issuer_PC$total_issuance

multiple_PC
[1] Inf Inf