Packages below are to help “tidy” the data within the tidyverse packages as well as incorporate geospatial data identifiers like iso3c country codes for joining different data tables. Additionally a country code function has been added to facilitate faster transformations of country level data.
Warning: package 'janitor' was built under R version 4.2.2
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
Show the code
library(here)
Warning: package 'here' was built under R version 4.2.2
here() starts at C:/Users/joeau/OneDrive - Johns Hopkins/SAIS/Year 2/Sustainable Finance/sais_sustainable_finance
Show the code
library(readxl)
Warning: package 'readxl' was built under R version 4.2.2
Show the code
library(rnaturalearth)
Warning: package 'rnaturalearth' was built under R version 4.2.2
Show the code
library(countrycode)
Warning: package 'countrycode' was built under R version 4.2.2
Show the code
library(wbstats)
Warning: package 'wbstats' was built under R version 4.2.2
Show the code
library(broom)
Warning: package 'broom' was built under R version 4.2.2
Show the code
#| echo: false#| warning: false#build functions to help generate locationscountry_name_regex_to_iso3c <-function(country_name) { country_name |>countrycode(origin ="country.name", destination ="iso3c",origin_regex =TRUE)}iso3c_to_country_name <-function(country_string) { country_string %>% countrycode::countrycode(origin ="iso3c", destination ="country.name")} character_num_to_numeric <-function(character_num) { character_num %>%# take out the commas stringr::str_remove_all(pattern =",") %>%# take out any blank spaces before or after the number stringr::str_trim() %>%# coerce to numericas.numeric()}iso3c_to_x <- purrr::partial(countrycode, origin ="iso3c")
Rows: 195 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): Country/Region, unit, 1990
dbl (28): 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, ...
ℹ 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.
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `iso3c = country_name_regex_to_iso3c(country)`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously: Data for, Data source, Micronesia
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `across(.cols = c("year", "co2_em"), .fns =
character_num_to_numeric)`.
Caused by warning in `character_num %>% stringr::str_remove_all(pattern = ",") %>% stringr::str_trim() %>%
as.numeric()`:
! NAs introduced by coercion
Show the code
scope
# A tibble: 5,655 × 7
country iso3c country_name flag unit year co2_em
<chr> <chr> <chr> <chr> <chr> <dbl> <dbl>
1 China CHN China "\U0001f1e8\U0001f1f3" MtCO2e 1990 2892.
2 United States USA United States "\U0001f1fa\U0001f1f8" MtCO2e 1990 5417.
3 India IND India "\U0001f1ee\U0001f1f3" MtCO2e 1990 1003.
4 Indonesia IDN Indonesia "\U0001f1ee\U0001f1e9" MtCO2e 1990 1227.
5 Russia RUS Russia "\U0001f1f7\U0001f1fa" MtCO2e 1990 2648.
6 Brazil BRA Brazil "\U0001f1e7\U0001f1f7" MtCO2e 1990 1639.
7 Japan JPN Japan "\U0001f1ef\U0001f1f5" MtCO2e 1990 1106.
8 Iran IRN Iran "\U0001f1ee\U0001f1f7" MtCO2e 1990 304.
9 Canada CAN Canada "\U0001f1e8\U0001f1e6" MtCO2e 1990 607.
10 Saudi Arabia SAU Saudi Arabia "\U0001f1f8\U0001f1e6" MtCO2e 1990 241.
# … with 5,645 more rows
# A tibble: 2,064 × 6
code country year country_ghg_all iso3c country_name
<chr> <chr> <dbl> <dbl> <chr> <chr>
1 Country <NA> 1995 NA <NA> <NA>
2 WLD World 1995 21367. <NA> <NA>
3 OECD OECD member countries 1995 13016. <NA> <NA>
4 AUS Australia 1995 278 AUS Australia
5 AUT Austria 1995 85.1 AUT Austria
6 BEL Belgium 1995 130. BEL Belgium
7 CAN Canada 1995 409. CAN Canada
8 CHL Chile 1995 39.9 CHL Chile
9 COL Colombia 1995 65.5 COL Colombia
10 CRI Costa Rica 1995 8.1 CRI Costa Rica
# … with 2,054 more rows
Show the code
#| echo: false#| warning: false#Joining OECD SCope 1 to Sovereign Debt Tableem_trade_less <- em_trade |>select(-c('code', 'country', 'country_name'))scope_1 <- scope |>inner_join(em_trade_less, by =c("iso3c", "year")) |>rowwise() |>mutate(scope1 =sum(c_across(co2_em:country_ghg_all)))
Warning in inner_join(scope, em_trade_less, by = c("iso3c", "year")): Each row in `x` is expected to match at most 1 row in `y`.
ℹ Row 1160 of `x` matches multiple rows.
ℹ If multiple matches are expected, set `multiple = "all"` to silence this
warning.
Show the code
scope_1
# A tibble: 3,024 × 9
# Rowwise:
country iso3c country_name flag unit year co2_em count…¹ scope1
<chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 China CHN China "\U0001f… MtCO… 1995 3961. 2614. 6574.
2 United States USA United States "\U0001f… MtCO… 1995 5730. 5374. 11103.
3 India IND India "\U0001f… MtCO… 1995 1224. 672. 1895.
4 Indonesia IDN Indonesia "\U0001f… MtCO… 1995 1339. 203. 1542.
5 Russia RUS Russia "\U0001f… MtCO… 1995 1918. 1026. 2944.
6 Brazil BRA Brazil "\U0001f… MtCO… 1995 1725. 250. 1975.
7 Japan JPN Japan "\U0001f… MtCO… 1995 1201. 1502. 2704.
8 Canada CAN Canada "\U0001f… MtCO… 1995 646. 409. 1055.
9 Saudi Arabia SAU Saudi Arabia "\U0001f… MtCO… 1995 289. 198 487.
10 Germany DEU Germany "\U0001f… MtCO… 1995 982. 1072. 2055.
# … with 3,014 more rows, and abbreviated variable name ¹country_ghg_all
Show the code
#| echo: false#| warning: false#Bring in Category D35 "Energy Imports" from OECD Emissions Table for Scope 2setwd("C:/Users/joeau/OneDrive - Johns Hopkins/SAIS/Year 2/Sustainable Finance/sais_sustainable_finance/week_7")scope_2_raw <-read_csv("scope_2.csv", skip =6) |>gather(Year, scope2, '1995':'2018')|>select(-c(2)) |>separate(col = Time, into =c("code", "country"), sep=': ') |>mutate(iso3c =country_name_regex_to_iso3c(country)) |>mutate(country_name =iso3c_to_country_name(iso3c)) |>filter('code'!="Country") |>rename("year"="Year") |>mutate(across(.cols =c("year"), .fns = character_num_to_numeric))
New names:
Rows: 80 Columns: 26
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(1): Time dbl (24): 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, ... lgl (1): ...2
ℹ 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.
• `` -> `...2`
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `iso3c = country_name_regex_to_iso3c(country)`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, Eastern Asia, EU28 excluding EU15, Euro area (19 countries), European Union (15 countries), European Union (27 countries), European Union (28 countries), Group of Twenty, Non-OECD economies and aggregates, OECD member countries, Rest of the World, Türkiye
Show the code
scope_2_raw
# A tibble: 1,920 × 6
code country year scope2 iso3c country_name
<chr> <chr> <dbl> <dbl> <chr> <chr>
1 Country <NA> 1995 NA <NA> <NA>
2 OECD OECD member countries 1995 10.1 <NA> <NA>
3 AUS Australia 1995 0.2 AUS Australia
4 AUT Austria 1995 0.6 AUT Austria
5 BEL Belgium 1995 1.4 BEL Belgium
6 CAN Canada 1995 15 CAN Canada
7 CHL Chile 1995 0 CHL Chile
8 COL Colombia 1995 0.1 COL Colombia
9 CRI Costa Rica 1995 0 CRI Costa Rica
10 CZE Czech Republic 1995 0.3 CZE Czechia
# … with 1,910 more rows
Show the code
#| echo: false#| warning: false#Joining OECD SCope 2 to Sovereign Debt Tablescope_2 <- scope_2_raw |>select(-c('code', 'country', 'country_name'))scope_1_2 <- scope_1 |>inner_join(scope_2, by =c("iso3c", "year")) |>rowwise() |>mutate(scope1 =sum(c_across(co2_em:country_ghg_all)))
Warning in inner_join(scope_1, scope_2, by = c("iso3c", "year")): Each row in `x` is expected to match at most 1 row in `y`.
ℹ Row 64 of `x` matches multiple rows.
ℹ If multiple matches are expected, set `multiple = "all"` to silence this
warning.
Show the code
scope_1_2
# A tibble: 24,192 × 10
# Rowwise:
country iso3c country_…¹ flag unit year co2_em count…² scope1 scope2
<chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 China CHN China "\U0… MtCO… 1995 3961. 2614. 6574. 1.1
2 United States USA United St… "\U0… MtCO… 1995 5730. 5374. 11103. 6.4
3 India IND India "\U0… MtCO… 1995 1224. 672. 1895. 0.2
4 Indonesia IDN Indonesia "\U0… MtCO… 1995 1339. 203. 1542. 0.1
5 Russia RUS Russia "\U0… MtCO… 1995 1918. 1026. 2944. 1.5
6 Brazil BRA Brazil "\U0… MtCO… 1995 1725. 250. 1975. 4
7 Japan JPN Japan "\U0… MtCO… 1995 1201. 1502. 2704. 1.5
8 Canada CAN Canada "\U0… MtCO… 1995 646. 409. 1055. 15
9 Saudi Arabia SAU Saudi Ara… "\U0… MtCO… 1995 289. 198 487. 0.1
10 Germany DEU Germany "\U0… MtCO… 1995 982. 1072. 2055. 4.3
# … with 24,182 more rows, and abbreviated variable names ¹country_name,
# ²country_ghg_all
# A tibble: 1,920 × 6
code country year scope_3_gross iso3c country_name
<chr> <chr> <dbl> <dbl> <chr> <chr>
1 Country <NA> 1995 NA <NA> <NA>
2 OECD OECD member countries 1995 1591. <NA> <NA>
3 AUS Australia 1995 62 AUS Australia
4 AUT Austria 1995 53.5 AUT Austria
5 BEL Belgium 1995 96.4 BEL Belgium
6 CAN Canada 1995 164. CAN Canada
7 CHL Chile 1995 14.1 CHL Chile
8 COL Colombia 1995 21.7 COL Colombia
9 CRI Costa Rica 1995 5.7 CRI Costa Rica
10 CZE Czech Republic 1995 27.8 CZE Czechia
# … with 1,910 more rows
# A tibble: 341,712 × 12
# Rowwise:
country iso3c count…¹ flag unit year co2_em count…² scope1 scope2 scope…³
<chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 China CHN China "\U0… MtCO… 1995 3961. 2614. 6574. 1.1 117.
2 United … USA United… "\U0… MtCO… 1995 5730. 5374. 11103. 6.4 787.
3 India IND India "\U0… MtCO… 1995 1224. 672. 1895. 0.2 47.5
4 Indones… IDN Indone… "\U0… MtCO… 1995 1339. 203. 1542. 0.1 56
5 Russia RUS Russia "\U0… MtCO… 1995 1918. 1026. 2944. 1.5 76.1
6 Brazil BRA Brazil "\U0… MtCO… 1995 1725. 250. 1975. 4 57.4
7 Japan JPN Japan "\U0… MtCO… 1995 1201. 1502. 2704. 1.5 480.
8 Canada CAN Canada "\U0… MtCO… 1995 646. 409. 1055. 15 164.
9 Saudi A… SAU Saudi … "\U0… MtCO… 1995 289. 198 487. 0.1 30.3
10 Germany DEU Germany "\U0… MtCO… 1995 982. 1072. 2055. 4.3 426.
# … with 341,702 more rows, 1 more variable: scope3 <dbl>, and abbreviated
# variable names ¹country_name, ²country_ghg_all, ³scope_3_gross
# A tibble: 341,712 × 11
# Rowwise:
country iso3c count…¹ flag unit year co2_em count…² scope1 scope2 scope3
<chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 China CHN China "\U0… MtCO… 1995 3961. 2614. 6574. 1.1 116
2 United S… USA United… "\U0… MtCO… 1995 5730. 5374. 11103. 6.4 780.
3 India IND India "\U0… MtCO… 1995 1224. 672. 1895. 0.2 47.3
4 Indonesia IDN Indone… "\U0… MtCO… 1995 1339. 203. 1542. 0.1 55.9
5 Russia RUS Russia "\U0… MtCO… 1995 1918. 1026. 2944. 1.5 74.6
6 Brazil BRA Brazil "\U0… MtCO… 1995 1725. 250. 1975. 4 53.4
7 Japan JPN Japan "\U0… MtCO… 1995 1201. 1502. 2704. 1.5 478
8 Canada CAN Canada "\U0… MtCO… 1995 646. 409. 1055. 15 149.
9 Saudi Ar… SAU Saudi … "\U0… MtCO… 1995 289. 198 487. 0.1 30.2
10 Germany DEU Germany "\U0… MtCO… 1995 982. 1072. 2055. 4.3 422.
# … with 341,702 more rows, and abbreviated variable names ¹country_name,
# ²country_ghg_all
Show the code
## Join in relevant WB datascope_1_2_3_wbnominal<-scope_1_2_3 |>inner_join(wb_gdp_nominal_clean)
#PCAF by industryggplot(hypothesis1, aes(x = GDP_measure, y = PCAF_em)) +geom_bin2d()
Show the code
# install.packages("hexbin")ggplot(hypothesis1, aes(x = GDP_measure, y = PCAF_em)) +geom_hex()
First, we’re looking at the country GDP profiles in our data set which appear highly concentrated in lower GDPs. Two possible adjustments to better view this data are smaller denonminations, the use of GDP per capita, or GNI to classify countries according to WB standards. Lets now look at GDP measured against PCAF scope emissions. Looking across GDP by country and PCAF Scope 1:3 emissions there is a clear trend in GDP growth and higher PCAF emissions. However, its not quite clear what Scope, the magnitude, and by whom. Looking at these trends there appear to be three different trends. Lets break out by scope.
Hypothesis 2: Scope Emission Types Vary by GDP growth
Show the code
EDA |>filter(GDP_type =="gdp") |>ggplot(aes(x = GDP_measure, y = PCAF_em, color = PCAF_scope)) +geom_point()
Scope 2 and 3 emissions to be much less depdent on GDP, which is possibly due to the fact that they are import related and possibly better measured by sector-specific capacity within country. Let’s see how Scope Emissions look over time when broken out by type.
Hypothesis 2: Pre-pandemic emissions were increasing across all PCAF scopes
ggplot(hypothesis2, aes(x = year, y = mean_em, color = PCAF_scope)) +geom_line() +facet_wrap(~ PCAF_scope, scales ="free_y")
While more current data is needed to see past 2018 and the pandemic recover efforts, these trends still demonstrate increases in scope post Paris Agreement. Interestingly, there is a decline in Scope 2 Emissions dating back to ~2007. Why is that? Further analysis needed on quantiles by countries and policies implemented in respective financial markets.