HW4

HW4

3.5.0.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)
library(dplyr)
library(ggplot2)

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.
# 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 <- 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
green_tidy <- 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
  )

cumulative_issuance <- green_tidy %>%
  group_by(region) %>%
  mutate(cumulative_issuance = cumsum(issuance_bn_usd),na.rm = TRUE)%>%
   arrange(desc(issuance_bn_usd))


cumulative_issuance_clean <- na.omit(cumulative_issuance)

ggplot(cumulative_issuance_clean, aes(x = reorder(region, cumulative_issuance), y = issuance_bn_usd, fill = region)) +
  geom_bar(stat = "identity") +
  labs(x = "Region", y = "Cumulative Issuance", fill = "Region") +
  ggtitle("Cumulative Issuance of Green Bonds by Region") +
  scale_y_continuous (labels = scales::label_dollar(suffix = " bn",prefix = "$", scale = 1))+
  theme_minimal()+
  coord_flip() 

3.5.0.2

green_debt_filtered <- green_debt %>% 
  clean_names()%>%
  filter(type_of_issuer != "Not Applicable")


green_tidy <- green_debt_filtered %>%
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "year",
    values_to = "issuance_bn_usd",
    names_transform = list(year=readr::parse_number),
    values_drop_na = TRUE
  )%>%
  group_by(type_of_issuer, year) %>%
  summarise(total_issuance_bn_usd = sum(issuance_bn_usd, na.rm = TRUE))
`summarise()` has grouped output by 'type_of_issuer'. You can override using
the `.groups` argument.
green_tidy %>%
  ggplot(aes(x = year, y = total_issuance_bn_usd, fill = type_of_issuer)) +
    geom_col() +
    scale_x_continuous(limits = c(2012, 2022)) +
    scale_y_continuous(labels = scales::label_dollar(suffix = " bn")) +
    labs(title = "Total Green Bond Issuance by Type of Issuer", x = "Year", y = "Total Issuance (USD in billion)") +
    theme_minimal() +
    theme(legend.position = "bottom")
Warning: Removed 27 rows containing missing values (`position_stack()`).
Warning: Removed 11 rows containing missing values (`geom_col()`).

3.5.0.3

use_of_proceed <-green_debt|> 
  clean_names() |> 
  filter(use_of_proceed != "Not Applicable")
print(unique(use_of_proceed$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"                                                                   
filtered_principal_currency <-green_debt |> 
  clean_names() |> 
  filter(principal_currency != "Not Applicable")

filtered_principal_currency|>
  group_by(principal_currency) |>
  summarize(count=n())
# A tibble: 50 × 2
   principal_currency                        count
   <chr>                                     <int>
 1 Argentinian Peso                              2
 2 Argentinian Unidades de Valor Adquisitivo     2
 3 Australian Dollar                             2
 4 Bangladeshi Taka                              2
 5 Brazilian Real                                2
 6 British Pound                                 2
 7 Canadian Dollar                               2
 8 Chilean Peso                                  2
 9 Chilean Unidad de Fomento                     2
10 Chinese Yuan                                  2
# ℹ 40 more rows

We can see that each currency has appeared twice in the dataset, all of them are in 2022.