Ticha_Sus_Fin_HW4

3. Data Tidying

3.5.0.1 Homework problem 1

  • Use the countrycode package to add the region as a variable to green_debt_subset.

  • Calculate the cumulative issuance of green bonds by region.

  • Use ggplot2 to make a data visualization comparing regional cumulative issuance.

  • Make your plot look professionally presentable, as we did above.

Load Libraries & Dataset

library(tidyverse)
Warning: package 'tidyr' was built under R version 4.2.3
Warning: package 'readr' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.1     
── 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)
library(dplyr)

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.

Add Region

Use the countrycode package to add the region as a variable to green_debt_subset.

green_debt <- green_debt %>%
  mutate(region = countrycode(Country, "country.name", "region"))
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `region = countrycode(Country, "country.name", "region")`.
Caused by warning:
! Some values were not matched unambiguously: World

Pivot from Wide to Long

green_bonds_long <- green_debt %>%
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = readr::parse_number,
    values_drop_na = TRUE
  )

Calculate Cumulative Issuance by Region

cumulative_issuance_by_region <- green_bonds_long %>%
  group_by(region) %>%
  summarize(issuance_bn_usd = sum(issuance_bn_usd, na.rm = TRUE)) %>%
  arrange(desc(issuance_bn_usd))

# Renaming NA values that emerged from world being a missing region to "world"
cumulative_issuance_by_region$region[is.na(cumulative_issuance_by_region$region)] <- "World"
Regions_without_world <- cumulative_issuance_by_region[cumulative_issuance_by_region$region != "World", ]

Visualize Cumulative Bond Issuance by Region

ggplot(Regions_without_world, aes(x = reorder(region, issuance_bn_usd), y = issuance_bn_usd)) +
  geom_col(fill = "lightgreen") +
  theme_minimal() +
  coord_flip() +
  geom_text(aes(
    label = sprintf("%.4g", issuance_bn_usd)), 
    position = position_stack(vjust = 0.5), color = "black") +
  scale_y_continuous(labels = scales::dollar_format(suffix = "bn", prefix = "$", scale = 1)) +
  labs(x = "Region", 
       y = "Cumulative Issuance (billion USD)", 
       title = "Cumulative Issuance by Region in Billion USD",
       subtitle = "Europeans and Central Asians issue a lot of bonds per capita!",
       caption = "Data: IMF Climate Change Dashboard | Insight: Me!")

3.5.0.2 Homework problem 2

  • Use the full green_debt dataset
  • Use clean_names() to make the variable names snake_case
  • Filter out observations where type_of_issuer is “Not Applicable”
green_debt_issuer <- green_debt %>%
  clean_names() %>%
  filter(type_of_issuer != "Not Applicable")
print(green_debt_issuer$type_of_issuer)
[1] "Banks"                        "International Organization"  
[3] "Local and state Government"   "Nonfinancial corporations"   
[5] "Other financial corporations" "Sovereign"                   
[7] "State owned entities"        

We can see here that we have 7 types of issuers, but that those are the only observations in the dataset. This means that type of issuer is “Not Applicable” for all but 7 issuers.

  • Use the tools taught in this chapter to provide a compelling data visualization and some repeatable factoids that provide actionable insights about green bond issuers.

Factoid 1: TOP 10 countries 2022 Issuance and Total Historical Issuance

# Factoid 1 TOP 10 countries 2022 Issuance and Total Historical Issuance
# Calculate total issuances by country and type
total_issuances_by_country <- green_bonds_long %>%
  group_by(Country, year) %>%
  summarise(issuance_bn_usd = sum(issuance_bn_usd), .groups = 'drop')

# Calculative total issuances by country over time
cumulative_issuance_by_country <- total_issuances_by_country %>%
  arrange(Country, year) %>%
  group_by(Country) %>%
  filter(Country != "World") %>%
  mutate(TotalIssuances = cumsum(issuance_bn_usd))

# Identify the top 10 countries based on TotalIssuances over time
top10_countries_issuances <- cumulative_issuance_by_country %>%
  ungroup() %>%
  arrange(Country, desc(year)) %>%
  distinct(Country, .keep_all = TRUE) %>%
  arrange(desc(TotalIssuances)) %>%
  slice(1:10)
print(top10_countries_issuances)
# A tibble: 10 × 4
   Country                year issuance_bn_usd TotalIssuances
   <chr>                 <dbl>           <dbl>          <dbl>
 1 China, P.R.: Mainland  2022           99.4           325. 
 2 Germany                2022           89.1           295. 
 3 France                 2022           33.3           271. 
 4 United States          2022           28.5           172. 
 5 Netherlands, The       2022           32.5           172. 
 6 United Kingdom         2022            7.90          122. 
 7 Italy                  2022           27.5            82.7
 8 Sweden                 2022           15.8            80.4
 9 Spain                  2022           13.2            74.4
10 Japan                  2022           23.0            61.8

Factoid 2: Top 5 countries by Issuance

# Factoid 2: Top 5 countries by Issuance
top5_countries_issuances <- cumulative_issuance_by_country %>%
  ungroup() %>%
  arrange(Country, desc(year)) %>%
  distinct(Country, .keep_all = TRUE) %>%
  arrange(desc(TotalIssuances)) %>%
  slice(1:5)
print(top5_countries_issuances)
# A tibble: 5 × 4
  Country                year issuance_bn_usd TotalIssuances
  <chr>                 <dbl>           <dbl>          <dbl>
1 China, P.R.: Mainland  2022            99.4           325.
2 Germany                2022            89.1           295.
3 France                 2022            33.3           271.
4 United States          2022            28.5           172.
5 Netherlands, The       2022            32.5           172.
top5_countries <- top5_countries_issuances %>%
  pull(Country)

Graph 1: Top 5 Countries’ Green Debt Issuance by Year

Though China is a late entrant to green bonds, it now outperforms every single country in the dataset. We can also see a significant dip in green bonds issued in Western top performers in 2022. This could be due to the economic slowdown, but also due to the ESG backlash that many Western countries are currently experiencing.

top5_countries_over_time <- green_bonds_long %>%
  filter(Country %in% top5_countries) %>%
  group_by(Country, year) %>%
  summarise(issuance_bn_usd = sum(issuance_bn_usd), .groups = 'drop')
ggplot(top5_countries_over_time, aes(x = year, y = issuance_bn_usd, group = Country, color = Country)) +
  geom_line() +  # Draw lines representing total yearly issuances
  labs(title = "Top 5 Countries' Green Bond Issuance Over Time",
       x = "Year",
       y = "Total Yearly Issuance (Billion USD)",
       color = "Country") +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 3, title.position = 'top', title.hjust = 0.5))

Factoid 3: Total Yearly Green Bond Issuance by Region

We can see here that Europe and Central Asia currently dominates the global issuance of green bonds. East Asia and Pacific, though a late mover in the industry, is catching up with Europe and Central Asia. Though North America houses the US — the largest economy in the world, it is trailing behind Europe and East Asia considerably, which means it could most likely be doing more towards sustainable transition.

library(scales)
Warning: package 'scales' was built under R version 4.2.3

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

    discard
The following object is masked from 'package:readr':

    col_factor
total_yearly_issuance_by_region <- green_bonds_long %>%
  group_by(region, year) %>%
  filter(Country != "World") %>%
  filter(year >=2010) %>%
  summarise(total_issuance = sum(issuance_bn_usd), .groups = 'drop')

ggplot(total_yearly_issuance_by_region, aes(x = year, y = total_issuance, color = region)) +
  geom_line() +
  labs(title = "Total Yearly Green Bond Issuance by Region",
       x = "Year",
       y = "Total Issuance (Billion USD)",
       color = "Region") +
  scale_x_continuous(breaks = seq(from = 2010, to = 2022, by = 1)) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 2, title.position = 'top', title.hjust = 0.5))

3.5.0.3 Homework problem 3:

  • Repeat the process from problem 2 for use_of_proceed and for principal_currency

    • What are green bond proceeds used for?

    The proceeds are being used for a range of activities, mainly relevant to sustainability, financing of sustainability and infrastructure projects, as well as public goods provision.

    • What do we know about the currency of issuance? Is that changing over time?

    We know that countries issue the bonds in their domestic currencies in 2022. But we don’t have data on past years and issuances designated “world”.

use_of_proceed_factoid <- green_debt %>%
  clean_names() %>%
  filter(use_of_proceed != "Not Applicable")
print(unique(use_of_proceed_factoid$use_of_proceed))
 [1] "Access to Essential Services"                                                      
 [2] "Acquiring and distribution of vaccine"                                             
 [3] "Acquisition"                                                                       
 [4] "Affordable Basic Infrastructure"                                                   
 [5] "Agriculture"                                                                       
 [6] "Alternative Energy"                                                                
 [7] "Aquatic Biodiversity Conservation"                                                 
 [8] "Capital expenditure"                                                               
 [9] "Capital expenditure/Financing expenses"                                            
[10] "Carbon reduction through reforestation and avoided deforestation"                  
[11] "China Urban Construction"                                                          
[12] "Circular Economy Adapted/Eco-efficient Products, Production Technologies/Processes"
[13] "Clean Transport"                                                                   
[14] "Climate Change Adaptation"                                                         
[15] "E-education programs - Education Projects"                                         
[16] "Economic Development"                                                              
[17] "Electric & Public Power"                                                           
[18] "Eligible Green Projects"                                                           
[19] "Employee stock ownership plan"                                                     
[20] "Energy Efficiency"                                                                 
[21] "Environmental Protection Projects"                                                 
[22] "Environmentally Sustainable Products"                                              
[23] "Equipment Upgrade/Construction"                                                    
[24] "Financing of Subordinated Loan"                                                    
[25] "Funding new technologies to reduce GHS emissions"                                  
[26] "Gas"                                                                               
[27] "General Purpose"                                                                   
[28] "General Purpose/Acquisition"                                                       
[29] "General Purpose/Refinance"                                                         
[30] "General Purpose/Working Capital"                                                   
[31] "Green Construction/Buildings"                                                      
[32] "Higher Education"                                                                  
[33] "Industrial Development"                                                            
[34] "Infrastructure"                                                                    
[35] "Land Preservation"                                                                 
[36] "Merger or Acquisition"                                                             
[37] "Other"                                                                             
[38] "Other Education"                                                                   
[39] "Other Housing"                                                                     
[40] "Other Public Service"                                                              
[41] "Other Transportation"                                                              
[42] "Pandemic"                                                                          
[43] "Pollution Control"                                                                 
[44] "Pollution Prevention & Control"                                                    
[45] "Production/Supply of Cannabis"                                                     
[46] "Project Finance"                                                                   
[47] "Property Expendit (acquisit/development)"                                          
[48] "Redeem Existing Bonds or Securities"                                               
[49] "Refinance/Financing expenses"                                                      
[50] "Renewable Energy Projects"                                                         
[51] "Repay Bank Loan or Bridge Financing"                                               
[52] "Repay Intercompany Debt"                                                           
[53] "Ship finance"                                                                      
[54] "Social Housing/Affordable Housing"                                                 
[55] "Socioeconomic Advancement And Empowerment"                                         
[56] "Solar projects"                                                                    
[57] "Sustainable Development Projects"                                                  
[58] "Sustainable Economic Growth"                                                       
[59] "Sustainable Forestry"                                                              
[60] "Sustainable Management of Land Use"                                                
[61] "Sustainable Management of Living Natural Resources"                                
[62] "Sustainable Transport"                                                             
[63] "Sustainable Water or Wastewater management"                                        
[64] "Terrestrial Biodiversity Conservation"                                             
[65] "The Belt and Road Initiative"                                                      
[66] "Waste Management"                                                                  
[67] "Water & Sewer"                                                                     
[68] "Wind projects"                                                                     
[69] "Working capital"                                                                   
principal_currency_factoid <- green_debt %>%
  clean_names() %>%
  filter(principal_currency != "Not Applicable")
print(unique(principal_currency_factoid$principal_currency))
 [1] "Argentinian Peso"                         
 [2] "Argentinian Unidades de Valor Adquisitivo"
 [3] "Australian Dollar"                        
 [4] "Bangladeshi Taka"                         
 [5] "Brazilian Real"                           
 [6] "British Pound"                            
 [7] "Canadian Dollar"                          
 [8] "Chilean Peso"                             
 [9] "Chilean Unidad de Fomento"                
[10] "Chinese Yuan"                             
[11] "Colombian Peso"                           
[12] "Czech Koruna"                             
[13] "Danish Krone"                             
[14] "Deutsche Mark"                            
[15] "Euro"                                     
[16] "European Currency Unit"                   
[17] "Fijian Dollar"                            
[18] "Hong Kong Dollar"                         
[19] "Hungarian Forint"                         
[20] "Icelandic Krona"                          
[21] "Indian Rupee"                             
[22] "Indonesian Rupiah"                        
[23] "Japanese Yen"                             
[24] "Kazakhstani Tenge"                        
[25] "Macanese Pataca"                          
[26] "Malaysian Ringgit"                        
[27] "Mexican Peso"                             
[28] "Mexican Unidad de Inversion"              
[29] "Moroccan Dirham"                          
[30] "Namibian Dollar"                          
[31] "New Zealand Dollar"                       
[32] "Nigerian Naira"                           
[33] "Norwegian Krone"                          
[34] "Peruvian Sol"                             
[35] "Philippine Peso"                          
[36] "Polish Zloty"                             
[37] "Romanian Leu"                             
[38] "Russian Ruble"                            
[39] "Singapore Dollar"                         
[40] "South African Rand"                       
[41] "South Korean Won"                         
[42] "Sri Lankan Rupee"                         
[43] "Swedish Krona"                            
[44] "Swiss Franc"                              
[45] "Taiwanese Dollar"                         
[46] "Thai Baht"                                
[47] "Turkish Lira"                             
[48] "Ukrainian Hryvnia"                        
[49] "US Dollar"                                
[50] "Vietnamese Dong"