Skip to content
Snippets Groups Projects
Commit 99826d62 authored by Ingram Jaccard's avatar Ingram Jaccard
Browse files

edit full code

parent 4905c491
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,7 @@ pacman::p_load(tidyverse, ...@@ -37,6 +37,7 @@ pacman::p_load(tidyverse,
wbstats, wbstats,
ISOcodes, ISOcodes,
viridis, viridis,
imputeTS,
hrbrthemes, hrbrthemes,
wesanderson, wesanderson,
glue, glue,
...@@ -656,7 +657,7 @@ satellite_FD = read.delim(paste0(data_dir_exiobase, "/IOT_", year_current, "_pxp ...@@ -656,7 +657,7 @@ satellite_FD = read.delim(paste0(data_dir_exiobase, "/IOT_", year_current, "_pxp
write.csv(satellite_FD, paste0(data_dir_exiobase, "/IOT_", year_current, "_pxp/satellite/F_hh.csv")) write.csv(satellite_FD, paste0(data_dir_exiobase, "/IOT_", year_current, "_pxp/satellite/F_hh.csv"))
## extract the relevant satellite extensions from the satellite table, calculate the 'total intensity ## extract the relevant satellite extensions from the satellite table, calculate the 'total intensity
## vectors' (and their row-wise breakdowns), and save to 'data_dir_exiobase' ## vectors' (and their row-wise breakdowns), and write them as .csv files to 'data_dir_exiobase'
# CO2 - combustion - air # CO2 - combustion - air
CO2_combustion_air = satellite[24,] CO2_combustion_air = satellite[24,]
...@@ -7482,38 +7483,103 @@ write_rds(results_formatted_with_direct_FD_fp, paste0(data_dir_income_stratified ...@@ -7482,38 +7483,103 @@ write_rds(results_formatted_with_direct_FD_fp, paste0(data_dir_income_stratified
```{r european-expenditure-deciles, eval = FALSE} ```{r european-expenditure-deciles, eval = FALSE}
knitr::opts_chunk$set(echo = FALSE, message=FALSE) # set target number of quantiles
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse,
janitor,
here,
wbstats,
ISOcodes,
viridis,
imputeTS,
hrbrthemes,
wesanderson,
glue)
target_eu_ntiles = 10 target_eu_ntiles = 10
#source(here("code", "helper_functions.R")) ##### main paper results (main paper method, EXIOBASE industry-by-industry version)
# 1) load MRIO result file # 1) load income-stratified-footprints formatted results file
dat_results_raw = read_rds(here("analysis", "preprocessing", "income-stratified-footprints", dat_results_raw = read_rds(here("analysis", "preprocessing", "income-stratified-footprints",
"results_formatted_method1_ixi.rds")) %>% "results_formatted_method1_ixi.rds")) %>%
ungroup() %>% ungroup() %>%
mutate(year= strtoi(year)) %>% mutate(year= strtoi(year)) %>%
rename(iso2 = geo) rename(iso2 = geo)
# get iso3 country codes to join with hh data # get iso3 country codes to join with household data
country_codes = ISOcodes::ISO_3166_1 %>% country_codes = ISOcodes::ISO_3166_1 %>%
select(iso2 = Alpha_2, iso3 = Alpha_3) %>% select(iso2 = Alpha_2, iso3 = Alpha_3) %>%
# resolve inconsistency between Eurostat and ISO for Greece and UK/Great Britain # resolve inconsistency between Eurostat and ISO for Greece and UK/Great Britain
mutate(iso2 = if_else(iso2=="GR", "EL", iso2)) %>% mutate(iso2 = if_else(iso2=="GR", "EL", iso2)) %>%
mutate(iso2 = if_else(iso2=="GB", "UK", iso2)) mutate(iso2 = if_else(iso2=="GB", "UK", iso2))
options(digits=4)
total_private_households_Eurostat = read.csv(here("/analysis/preprocessing/income-stratified-footprints/lfst_hhnhtych_1_Data.csv")) %>%
filter(!(GEO %in% c("European Union - 27 countries (from 2020)",
"Euro area - 19 countries (from 2015)",
"European Union - 28 countries (2013-2020)",
"European Union - 15 countries (1995-2004)"))) %>%
mutate(geo = dplyr::recode(GEO,
"Belgium" = "BE",
"Bulgaria" = "BG",
"Czechia" = "CZ",
"Denmark" = "DK",
"Germany (until 1990 former territory of the FRG)" = "DE",
"Estonia" = "EE",
"Ireland" = "IE",
"Greece" = "EL",
"Spain" = "ES",
"France" = "FR",
"Croatia" = "HR",
"Italy" = "IT",
"Cyprus" = "CY",
"Latvia" = "LV",
"Lithuania" = "LT",
"Luxembourg" = "LU",
"Hungary" = "HU",
"Malta" = "MT",
"Netherlands" = "NL",
"Austria" = "AT",
"Poland" = "PL",
"Portugal" = "PT",
"Romania" = "RO",
"Slovenia" = "SI",
"Slovakia" = "SK",
"Finland" = "FI",
"Sweden" = "SE",
"United Kingdom" = "UK",
"Montenegro" = "ME",
"North Macedonia" = "MK",
"Serbia" = "RS",
"Turkey" = "TR")) %>%
select(TIME,geo,Value) %>%
rename(year = TIME, total_private_households = Value) %>%
mutate(total_private_households = parse_number(total_private_households),
total_private_households = as.numeric(total_private_households),
total_private_households = total_private_households*1000)
total_private_households_Norway = read.csv(here("/analysis/preprocessing/income-stratified-footprints/Privathusholdninger.csv")) %>%
gather(year, total_private_households, Private.households.2005:Private.households.2019) %>%
mutate(geo = dplyr::recode(region,
"0 The whole country" = "NO"),
year = dplyr::recode(year,
"Private.households.2005" = 2005,
"Private.households.2006" = 2006,
"Private.households.2007" = 2007,
"Private.households.2008" = 2008,
"Private.households.2009" = 2009,
"Private.households.2010" = 2010,
"Private.households.2011" = 2011,
"Private.households.2012" = 2012,
"Private.households.2013" = 2013,
"Private.households.2014" = 2014,
"Private.households.2015" = 2015,
"Private.households.2016" = 2016,
"Private.households.2017" = 2017,
"Private.households.2018" = 2018,
"Private.households.2019" = 2019)) %>%
select(year,geo,total_private_households)
total_private_households = rbind(total_private_households_Eurostat,
total_private_households_Norway) %>%
mutate(geo = as.character(geo),
year = as.numeric(year),
total_private_households = as.numeric(total_private_households))
#write_csv(total_private_households, "../data/total_private_households.csv")
options(digits=2)
# 2) load Eurostat household data - should show how I get to 'total_private_households.csv' - see code chunk in SI - move to here. # 2) load Eurostat household data - should show how I get to 'total_private_households.csv' - see code chunk in SI - move to here.
hh_data = read_csv(here("analysis", "preprocessing", "income-stratified-footprints", hh_data = read_csv(here("analysis", "preprocessing", "income-stratified-footprints",
"total_private_households.csv")) %>% "total_private_households.csv")) %>%
......
region,Private households 2005,Private households 2006,Private households 2007,Private households 2008,Private households 2009,Private households 2010,Private households 2011,Private households 2012,Private households 2013,Private households 2014,Private households 2015,Private households 2016,Private households 2017,Private households 2018,Private households 2019
0 The whole country,2010999,2036890,2064841,2104531,2142638,2170893,2201787,2226046,2258794,2286445,2316647,2348797,2376971,2409257,2439242
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment