Homework 6

Author

Sophia Wang

Packages setup

library(readr)
library(countrycode)
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(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ 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(readxl)

Data setup

Scope 1:

foe the scope 1, i selected the data from climatewatchdata. org and the data describes total GHG emissions with LULUCF from UNFCCC.

emission <- read_csv("~/SPR24_SUSFIN/historical_emissions.csv")
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
Rows: 1387 Columns: 17
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (16): ISO, Country, Data source, Sector, Gas, Unit, 2021, 2020, 2019, 20...
dbl  (1): 2016

ℹ 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.
View(emission)

emission
# A tibble: 1,387 × 17
   ISO    Country   `Data source` Sector Gas   Unit  `2021` `2020` `2019` `2018`
   <chr>  <chr>     <chr>         <chr>  <chr> <chr> <chr>  <chr>  <chr>  <chr> 
 1 ANNEXI Annex-I … UNFCCC_AI     Total… Aggr… MtCO… 15400… 15244… 16400… 16783…
 2 ANNEXI Annex-I … UNFCCC_AI     Total… Aggr… MtCO… 13737… 13435… 14686… 14969…
 3 ANNEXI Annex-I … UNFCCC_AI     Total… CO2   MtCO… 12351… 12075… 13162… 13506…
 4 ANNEXI Annex-I … UNFCCC_AI     Energy Aggr… MtCO… 12210… 11981… 13101… 13445…
 5 ANNEXI Annex-I … UNFCCC_AI     Energy CO2   MtCO… 11461… 11202… 12269… 12597…
 6 ANNEXI Annex-I … UNFCCC_AI     Total… CO2   MtCO… 10525… 10101… 11288… 11522…
 7 USA    United S… UNFCCC_AI     Total… Aggr… MtCO… 6340.… 6025.… 6617.… 6754.…
 8 USA    United S… UNFCCC_AI     Total… Aggr… MtCO… 5586.0 5249.… 5913.… 5989.7
 9 USA    United S… UNFCCC_AI     Energy Aggr… MtCO… 5196.… 4893.… 5460.… 5589.…
10 USA    United S… UNFCCC_AI     Total… CO2   MtCO… 5032.… 4714.… 5262.… 5377.8
# ℹ 1,377 more rows
# ℹ 7 more variables: `2017` <chr>, `2016` <dbl>, `2015` <chr>, `2014` <chr>,
#   `2013` <chr>, `2012` <chr>, `2011` <chr>
emission_country <- emission |>
  select(-"Data source") |>
  filter(ISO != "ANNEXI") |>
  filter(ISO != "EUU") |>
  filter(grepl("CO2|Aggregate GHGs", Gas)) |>
  filter(Sector == "Total GHG emissions with LULUCF") 

emission_country
# A tibble: 86 × 16
   ISO   Country    Sector Gas   Unit  `2021` `2020` `2019` `2018` `2017` `2016`
   <chr> <chr>      <chr>  <chr> <chr> <chr>  <chr>  <chr>  <chr>  <chr>   <dbl>
 1 USA   United St… Total… Aggr… MtCO… 5586.0 5249.… 5913.… 5989.7 5787.…  5763.
 2 USA   United St… Total… CO2   MtCO… 4200.… 3862.… 4493.… 4548.3 4369.…  4379.
 3 RUS   Russia     Total… Aggr… MtCO… 1650.… 1503.… 1586.… 1567.… 1479.…  1419.
 4 RUS   Russia     Total… CO2   MtCO… 1158.… 1039.2 1113.0 1085.… 1024.…   983.
 5 JPN   Japan      Total… Aggr… MtCO… 1116.4 1093.… 1157.… 1186.… 1230.…  1248.
 6 JPN   Japan      Total… CO2   MtCO… 1009.… 987.73 1053.… 1085.… 1130.…  1150.
 7 DEU   Germany    Total… Aggr… MtCO… 764.36 735.12 787.81 838.51 870.88   885.
 8 DEU   Germany    Total… CO2   MtCO… 675.07 643.74 692.96 739.35 767.61   780.
 9 CAN   Canada     Total… Aggr… MtCO… 653.13 645.4  704.86 713.32 696.01   694.
10 CAN   Canada     Total… CO2   MtCO… 519.0  508.62 558.87 564.71 549.24   546.
# ℹ 76 more rows
# ℹ 5 more variables: `2015` <chr>, `2014` <chr>, `2013` <chr>, `2012` <chr>,
#   `2011` <chr>
emission_long <- emission_country |>
  mutate(across(`2011`:`2021`, ~parse_number(as.character(.)), .names = "year_{.col}")) |>
  pivot_longer(
    cols = starts_with("year_"),
    names_to = "year",
    values_to = "emission_value",
    names_prefix = "year_",
    values_drop_na = TRUE
  )
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `across(`2011`:`2021`, ~parse_number(as.character(.)), .names =
  "year_{.col}")`.
Caused by warning:
! 2 parsing failures.
row col expected actual
 85  -- a number    N/A
 86  -- a number    N/A
emission_domestic <- emission_long |>
  mutate(scope = "Scope 1") |>
  mutate(sector = "Domestic Emissions") |>
  select('ISO','Country','scope','sector', 'Gas','Unit','year','emission_value') |>
  rename(iso3 = ISO) 

emission_domestic
# A tibble: 944 × 8
   iso3  Country       scope   sector           Gas   Unit  year  emission_value
   <chr> <chr>         <chr>   <chr>            <chr> <chr> <chr>          <dbl>
 1 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2011           6116.
 2 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2012           5885.
 3 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2013           6092.
 4 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2014           6130.
 5 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2015           6066.
 6 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2016           5763.
 7 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2017           5788.
 8 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2018           5990.
 9 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2019           5914.
10 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2020           5250.
# ℹ 934 more rows

The data I have collected here is from OCED and the data describes total CO2 emissions embodied in gross exports.

emissions1_export <- read_excel("~/SPR24_SUSFIN/Emissions of Exports of Goods and Services.xlsx")

emissions1_export
# A tibble: 84 × 11
   Country `2009` `2010` `2011` `2012` `2013` `2014` `2015` `2016` `2017` `2018`
   <chr>    <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
 1 OECD: …   0      0      0      0      0      0      0      0      0      0   
 2 AUS: A…  53.8   50.3   53.2   52.2   48.4   49.4   42.8   39.2   42.7   45.7 
 3 AUT: A…  35.0   46.0   48.9   45.9   44.7   41.9   41.0   40.7   44.8   44.8 
 4 BEL: B…  67.1   75.4   76.1   67.9   66.3   64.2   63.4   64.6   66.7   67.8 
 5 CAN: C… 193.   198.   212.   216.   221.   232.   224.   226.   230.   237.  
 6 CHL: C…  20.3   22.3   22.3   19.0   18.6   17.3   16.5   15.6   16.2   21.7 
 7 COL: C…   8.41   9.64  12.0   11.9   10.8   13.9   14.4   15.9   13.3   13.3 
 8 CRI: C…   2.14   2.20   2.20   2.27   2.38   2.24   2.16   2.43   2.50   2.69
 9 CZE: C…  55.5   60.1   63.8   62.4   57.8   57.0   57.7   57.3   59.1   60.4 
10 DNK: D…  44.3   45.0   42.0   36.8   37.0   33.3   33.1   32.1   32.5   32.1 
# ℹ 74 more rows
emission1_country <- emissions1_export |>
  mutate(scope = "Scope 1") |>
  mutate(Gas = "CO2") |>
  mutate(Unit = "MtCO₂e") |>
  mutate(sector = "Exports  Emissions") |>
  mutate(Country = gsub(".*: ", "",Country)) |>
  mutate(iso3 = countrycode(Country, "country.name", "iso3c")) |>
  filter(iso3 != "NA") |>
  select(iso3, Country, scope, sector, Gas, everything())
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `iso3 = countrycode(Country, "country.name", "iso3c")`.
Caused by warning:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, Data extracted on 04 Mar 2024 02:55 UTC (GMT) from OECD.Stat, East and Southeastern Asia, Eastern Asia, EU28 excluding EU15, Euro area (19 countries), Europe, European Union (15 countries), European Union (27 countries), European Union (28 countries), Group of Twenty, Non-OECD economies and aggregates, North America, OECD member countries, Other regions, Rest of the World, South and Central America
emission1_long <- emission1_country |>
  mutate(across(`2009`:`2018`, ~parse_number(as.character(.)), .names = "year_{.col}")) |>
  pivot_longer(
    cols = starts_with("year_"),
    names_to = "year",
    values_to = "emission_value",
    names_prefix = "year_",
    values_drop_na = TRUE
  ) 

emission_export <- emission1_long |>
  select('iso3','Country','scope','sector', 'Gas','Unit','year','emission_value')

emission_export
# A tibble: 660 × 8
   iso3  Country   scope   sector             Gas   Unit   year  emission_value
   <chr> <chr>     <chr>   <chr>              <chr> <chr>  <chr>          <dbl>
 1 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2009            53.8
 2 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2010            50.3
 3 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2011            53.2
 4 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2012            52.2
 5 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2013            48.4
 6 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2014            49.4
 7 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2015            42.8
 8 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2016            39.2
 9 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2017            42.7
10 AUS   Australia Scope 1 Exports  Emissions CO2   MtCO₂e 2018            45.7
# ℹ 650 more rows

Scope 2:

The data I have collected here is from OCED and the data describes total CO2 emissions about Electricity, gas, steam, and air conditioning supply.

emission_2 <- read_excel("~/SPR24_SUSFIN/Grid-supplied electricity, steam and cooling imports.xlsx")

emission_2 
# A tibble: 85 × 11
   Country     `2009` `2010` `2011` `2012` `2013` `2014`  `2015`  `2016`  `2017`
   <chr>        <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>   <dbl>   <dbl>   <dbl>
 1 WLD: World 4618.   4.82e3 4.77e3 4.71e3 4.64e3 4.51e3 4.34e+3 4.28e+3 4.21e+3
 2 OECD: OEC… 4440.   4.61e3 4.53e3 4.46e3 4.38e3 4.26e3 4.09e+3 4.06e+3 3.97e+3
 3 AUS: Aust…  187.   1.82e2 1.71e2 1.71e2 1.65e2 1.49e2 1.56e+2 1.62e+2 1.56e+2
 4 AUT: Aust…   16.3  1.51e1 1.52e1 1.38e1 1.30e1 1.22e1 1.22e+1 1.17e+1 1.24e+1
 5 BEL: Belg…   23.0  2.51e1 2.33e1 2.39e1 2.20e1 2.05e1 2.12e+1 2.06e+1 2.12e+1
 6 CAN: Cana…  117.   1.28e2 1.25e2 1.19e2 1.16e2 1.12e2 1.03e+2 1.00e+2 9.87e+1
 7 CHL: Chile   17.3  1.84e1 2.17e1 2.41e1 2.60e1 2.13e1 2.38e+1 2.48e+1 2.44e+1
 8 COL: Colo…   10.6  1.19e1 8.81e0 1.03e1 1.45e1 1.43e1 1.48e+1 1.42e+1 8.77e+0
 9 CRI: Cost…    0.88 1.20e0 1.34e0 1.38e0 1.65e0 1.51e0 9.14e-1 9.24e-1 7.99e-1
10 CZE: Czec…   43.1  4.53e1 4.48e1 4.16e1 4.02e1 3.80e1 3.84e+1 4.06e+1 3.91e+1
# ℹ 75 more rows
# ℹ 1 more variable: `2018` <dbl>
emission2_country <- emission_2 |>
  mutate(scope = "Scope 2") |>
  mutate(Gas = "CO2") |>
  mutate(Unit = "MtCO₂e") |>
  mutate(sector = "Import  Emissions") |>
  mutate(Country = gsub(".*: ", "",Country)) |>
  mutate(iso3 = countrycode(Country, "country.name", "iso3c")) |>
  filter(iso3 != "NA") |>
  select(iso3, Country, scope, sector, Gas, everything())
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `iso3 = countrycode(Country, "country.name", "iso3c")`.
Caused by warning:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, Data extracted on 04 Mar 2024 02:49 UTC (GMT) from OECD.Stat, East and Southeastern Asia, Eastern Asia, EU28 excluding EU15, Euro area (19 countries), Europe, European Union (15 countries), European Union (27 countries), European Union (28 countries), Group of Twenty, Non-OECD economies and aggregates, North America, OECD member countries, Other regions, Rest of the World, South and Central America, World
emission2_long <- emission2_country |>
  mutate(across(`2009`:`2018`, ~parse_number(as.character(.)), .names = "year_{.col}")) |>
  pivot_longer(
    cols = starts_with("year_"),
    names_to = "year",
    values_to = "emission_value",
    names_prefix = "year_",
    values_drop_na = TRUE
  ) 

emission_import <- emission2_long |>
  select('iso3','Country','scope','sector','Gas','Unit','year','emission_value')

emission_import
# A tibble: 660 × 8
   iso3  Country   scope   sector            Gas   Unit   year  emission_value
   <chr> <chr>     <chr>   <chr>             <chr> <chr>  <chr>          <dbl>
 1 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2009            187.
 2 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2010            182.
 3 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2011            171.
 4 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2012            171.
 5 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2013            165.
 6 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2014            149.
 7 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2015            156.
 8 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2016            162.
 9 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2017            156.
10 AUS   Australia Scope 2 Import  Emissions CO2   MtCO₂e 2018            152.
# ℹ 650 more rows

Scope 3:

The data I have collected here is from OCED and the data describes the total service industry.

Non_energy_emission <- read_excel("~/SPR24_SUSFIN/Non-energy imports.xlsx")

Non_energy_emission
# A tibble: 79 × 11
   Country `2009` `2010` `2011` `2012` `2013` `2014` `2015` `2016` `2017` `2018`
   <chr>    <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
 1 OECD: … 495.   539.   562.   524.   526.   512.   522.   530.   537.   533.  
 2 AUS: A…  28.6   29.2   35.8   39.8   39.5   34.6   31.4   29.8   30.3   30.2 
 3 AUT: A…  17.9   21.0   21.6   20.5   20.7   20.5   20.2   20.8   21.3   22.2 
 4 BEL: B…  26.6   34.9   37.2   35.9   35.0   37.0   33.9   35.2   36.5   36.2 
 5 CAN: C…  47.0   57.2   60.0   57.3   58.1   53.2   48.8   48.9   50.4   49.8 
 6 CHL: C…   6.44   8.12   9.64   7.86   8.10   6.72   5.97   6.00   5.88   5.90
 7 COL: C…   5.68   5.68   6.15   5.80   4.99   8.24   8.11   7.96   7.92   8.19
 8 CRI: C…   1.42   1.76   1.70   1.85   1.90   1.86   2.26   2.38   2.44   2.37
 9 CZE: C…   8.80   9.89  10.5    9.75   9.14   9.13   9.48   9.37   9.85   9.89
10 DNK: D…  27.8   25.2   23.8   23.1   24.9   24.1   23.6   23.2   22.3   23.4 
# ℹ 69 more rows
emission3_country <- Non_energy_emission |>
  mutate(scope = "Scope 3") |>
  mutate(Gas = "CO2") |>
  mutate(Unit = "MtCO₂e") |>
  mutate(sector = "Non-Energy  Emissions") |>
  mutate(Country = gsub(".*: ", "",Country)) |>
  mutate(iso3 = countrycode(Country, "country.name", "iso3c")) |>
  filter(iso3 != "NA") |>
  select(iso3, Country, scope, sector, Gas, everything())
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `iso3 = countrycode(Country, "country.name", "iso3c")`.
Caused by warning:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, Data extracted on 04 Mar 2024 03:51 UTC (GMT) from OECD.Stat, 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
emission3_long <- emission3_country |>
  mutate(across(`2009`:`2018`, ~parse_number(as.character(.)), .names = "year_{.col}")) |>
  pivot_longer(
    cols = starts_with("year_"),
    names_to = "year",
    values_to = "emission_value",
    names_prefix = "year_",
    values_drop_na = TRUE
  ) 

emission_non_energy <- emission3_long |>
  select('iso3','Country','scope','sector','Gas','Unit','year','emission_value')

emission_non_energy
# A tibble: 660 × 8
   iso3  Country   scope   sector               Gas   Unit  year  emission_value
   <chr> <chr>     <chr>   <chr>                <chr> <chr> <chr>          <dbl>
 1 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2009            28.6
 2 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2010            29.2
 3 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2011            35.8
 4 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2012            39.8
 5 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2013            39.5
 6 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2014            34.6
 7 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2015            31.4
 8 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2016            29.8
 9 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2017            30.3
10 AUS   Australia Scope 3 Non-Energy  Emissio… CO2   MtCO… 2018            30.2
# ℹ 650 more rows

Combine data:

emission_tidy <- bind_rows(emission_domestic) |> 
  bind_rows(emission_export) |>
  bind_rows(emission_import)|>
  bind_rows(emission_non_energy) 
  

emission_tidy
# A tibble: 2,924 × 8
   iso3  Country       scope   sector           Gas   Unit  year  emission_value
   <chr> <chr>         <chr>   <chr>            <chr> <chr> <chr>          <dbl>
 1 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2011           6116.
 2 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2012           5885.
 3 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2013           6092.
 4 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2014           6130.
 5 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2015           6066.
 6 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2016           5763.
 7 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2017           5788.
 8 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2018           5990.
 9 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2019           5914.
10 USA   United States Scope 1 Domestic Emissi… Aggr… MtCO… 2020           5250.
# ℹ 2,914 more rows

The echo: false option disables the printing of code (only output is displayed).