DataTidy HW

Author

Zixi Fan

Data Tidy HW

Load Data
library(tidyr)
library(dplyr)

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

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(countrycode)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ readr     2.1.4
✔ ggplot2   3.4.4     ✔ stringr   1.5.1
✔ lubridate 1.9.3     ✔ tibble    3.2.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(readr)
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.
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>, …

Question 1:

# Add the region as a variable to green_debt_subset
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}")) 

green_debt_subset |> 
  pivot_longer(
    cols = matches("f\\d{4}")
  )
# A tibble: 3,103 × 5
   country   iso3  indicator                       name  value
   <chr>     <chr> <chr>                           <chr> <dbl>
 1 Argentina ARG   Green Bond Issuances by Country f1985    NA
 2 Argentina ARG   Green Bond Issuances by Country f1986    NA
 3 Argentina ARG   Green Bond Issuances by Country f1987    NA
 4 Argentina ARG   Green Bond Issuances by Country f1990    NA
 5 Argentina ARG   Green Bond Issuances by Country f1991    NA
 6 Argentina ARG   Green Bond Issuances by Country f1992    NA
 7 Argentina ARG   Green Bond Issuances by Country f1993    NA
 8 Argentina ARG   Green Bond Issuances by Country f1994    NA
 9 Argentina ARG   Green Bond Issuances by Country f1999    NA
10 Argentina ARG   Green Bond Issuances by Country f2000    NA
# ℹ 3,093 more rows
green_debt_subset$region <- countrycode(green_debt_subset$country, "country.name", "region")

# Calculate the cumulative issuance of green bonds by region
green_debt_long <- green_debt_subset %>%
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "Year",
    values_to = "Issuance" # Naming the column with values as 'Issuance'
  )
cumulative_issuance_by_region <- green_debt_long %>%
  group_by(region) %>%
  summarize(CumulativeIssuance = sum(Issuance, na.rm = TRUE))

# Use ggplot2 to make a data visualization comparing regional cumulative issuance.
ggplot(cumulative_issuance_by_region, aes(x = reorder(region, -CumulativeIssuance), y = CumulativeIssuance, fill = region)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  labs(title = "Cumulative Green Bond Issuance by Region",
       x = "Region",
       y = "Cumulative Issuance (USD)") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Question 2:

# Use clean_names() to make the variable names snake_case
green_debt <- green_debt %>%
  clean_names() 

# Filter out observations where type_of_issuer is “Not Applicable”
green_debt_clean <- green_debt %>%
  filter(type_of_issuer != "Not Applicable")

green_debt_clean 
# A tibble: 7 × 42
  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 Issua… Bill… Refin… ECFFI    Green B…
2       348 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
3       349 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
4       350 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
5       351 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
6       352 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
7       353 World   <NA>  WLD   Green Bond Issua… Bill… Refin… ECFFI    Green B…
# ℹ 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>,
#   f2016 <dbl>, f2017 <dbl>, f2018 <dbl>, f2019 <dbl>, f2020 <dbl>, …

Question 2 continue

# Visualization: Total Issuance Volume by Issuer Type Over Time
green_debt_long <- green_debt_clean %>%
  pivot_longer(
    cols = starts_with("f"),
    names_to = "year",
    values_to = "issuance_volume",
    names_prefix = "f",
    names_transform = list(year = as.integer)
  ) %>%
  filter(!is.na(issuance_volume))

issuance_by_type_year <- green_debt_long %>%
  group_by(type_of_issuer, year) %>%
  summarize(total_issuance = sum(issuance_volume, na.rm = TRUE), .groups = 'drop')

ggplot(issuance_by_type_year, aes(x = year, y = total_issuance, color = type_of_issuer)) +
  geom_line() +
  theme_minimal() +
  labs(title = "Total Issuance Volume of Green Bonds by Issuer Type Over Time",
       x = "Year",
       y = "Total Issuance Volume (USD)",
       color = "Type of Issuer")

Question 3:

  1. For use_of_proceed
# for use_of_proceed 
green_debt |> 
  clean_names() |> 
  filter(use_of_proceed != "Not Applicable")
# A tibble: 138 × 42
   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
# ℹ 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>, …
# Visualization:
green_debt_long <- green_debt %>%
  pivot_longer(
    cols = starts_with("f"),  
    names_to = "year",  
    names_prefix = "f",  
    values_to = "value"  
  ) %>%
  mutate(year = as.integer(year)) 

green_debt_time_series <- green_debt_long %>%
  group_by(year) %>%
  summarise(total_issuance = n())

ggplot(green_debt_time_series, aes(x = year, y = total_issuance, color='red')) +
  geom_line() +
  geom_point() +
  labs(title = "Trend of Green Bond Issuances Over Time",
       x = "Year",
       y = "Number of Issuances") +
  theme_minimal()

  1. For principal_currency
green_debt |> 
  clean_names() |> 
  filter(principal_currency != "Not Applicable")
# A tibble: 100 × 42
   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
# ℹ 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>, …
# Total issuances over time
total_issuance_per_year <- green_debt_long %>%
  group_by(year) %>%
  summarise(total_value = sum(value, na.rm = TRUE))

ggplot(total_issuance_per_year, aes(x = year, y = total_value)) +
  geom_line() +
  geom_point() +
  labs(title = "Total Issuance Value Over Time",
       x = "Year",
       y = "Total Value") +
  theme_minimal()

Green bond proceeds are used for helping investors and policymakers understand where green finance is most actively being directed.

Currency of issuance is indeed changing over time, shown in the graph above. And the changes reflect shifts in the green bond market, like increasing activity in certain regions.