From 22d79f3acc202b88b77690fdb06a114ec3c3cc2c Mon Sep 17 00:00:00 2001
From: jaccard <jaccard@pik-potsdam.de>
Date: Tue, 15 Dec 2020 19:10:45 -0800
Subject: [PATCH] edit full code

---
 analysis/paper/si.Rmd                         |  2 +-
 ...xiobase_T_labels_ixi_w_coicop_mapping.csv} |  0
 analysis/preprocessing/full_code.Rmd          | 66 +++++--------------
 3 files changed, 18 insertions(+), 50 deletions(-)
 rename analysis/preprocessing/{Exiobase_T_labels_ixi_w_coicop_mapping_no_rent.csv => Exiobase_T_labels_ixi_w_coicop_mapping.csv} (100%)

diff --git a/analysis/paper/si.Rmd b/analysis/paper/si.Rmd
index 7539ad3..002fe28 100644
--- a/analysis/paper/si.Rmd
+++ b/analysis/paper/si.Rmd
@@ -272,7 +272,7 @@ Table S4 shows our mapping between the EUROSTAT HBS consumption categories and t
 
 ```{r tableS4}
 
-labels = read.csv(here("/analysis/preprocessing/Exiobase_T_labels_ixi_w_coicop_mapping_no_rent.csv")) %>%
+labels = read.csv(here("/analysis/preprocessing/Exiobase_T_labels_ixi_w_coicop_mapping.csv")) %>%
   select(V2,coicop,five_sectors) %>%
   unique()
 
diff --git a/analysis/preprocessing/Exiobase_T_labels_ixi_w_coicop_mapping_no_rent.csv b/analysis/preprocessing/Exiobase_T_labels_ixi_w_coicop_mapping.csv
similarity index 100%
rename from analysis/preprocessing/Exiobase_T_labels_ixi_w_coicop_mapping_no_rent.csv
rename to analysis/preprocessing/Exiobase_T_labels_ixi_w_coicop_mapping.csv
diff --git a/analysis/preprocessing/full_code.Rmd b/analysis/preprocessing/full_code.Rmd
index c4d7e84..16dcc3c 100644
--- a/analysis/preprocessing/full_code.Rmd
+++ b/analysis/preprocessing/full_code.Rmd
@@ -3196,9 +3196,9 @@ results_formatted = results_recombined %>%
 
 #write_rds(results_formated, here("/results_formated.rds"))
 
-write.csv(results_formatted, paste0(data_dir_income_stratified_footprints, "/results_formatted_method1_ixi_pps_hh_no_rent.csv"))
+write.csv(results_formatted, paste0(data_dir_income_stratified_footprints, "/results_formatted_method1_ixi.csv"))
 
-write_rds(results_formatted, paste0(data_dir_income_stratified_footprints, "/results_formatted_method1_ixi_pps_hh_no_rent.rds"))
+write_rds(results_formatted, paste0(data_dir_income_stratified_footprints, "/results_formatted_method1_ixi.rds"))
 
 
 #write.csv(results_formatted, paste0(data_dir_income_stratified_footprints, "/results_formatted_method1_ixi_pps_ae.csv"))
@@ -7554,7 +7554,7 @@ write.csv(results_formatted_with_direct_FD_fp, paste0(data_dir_income_stratified
 
 ```
 
-# European exp deciles
+# European expenditure deciles
 
 ```{r european-expenditure-deciles, eval = FALSE}
 
@@ -7574,11 +7574,11 @@ pacman::p_load(tidyverse,
 
 target_eu_ntiles = 10
 
-source(here("code", "helper_functions.R"))
-
+#source(here("code", "helper_functions.R"))
 
 # 1) load MRIO result file
-dat_results_raw = read_rds(here("data", "results_formatted_method1_ixi_pps_hh_no_rent.rds")) %>%
+dat_results_raw = read_rds(here("analysis", "preprocessing", "income-stratified-footprints",
+                                "results_formatted_method1_ixi.rds")) %>%
   ungroup() %>%
   mutate(year= strtoi(year)) %>%
   rename(iso2 = geo)
@@ -7591,7 +7591,8 @@ country_codes = ISOcodes::ISO_3166_1 %>%
   mutate(iso2 = if_else(iso2=="GB", "UK", iso2))
 
 # 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("data", "total_private_households.csv")) %>%
+hh_data = read_csv(here("analysis", "preprocessing", "income-stratified-footprints", 
+                        "total_private_households.csv")) %>%
   mutate(imputed = if_else(is.na(total_private_households), TRUE, FALSE)) %>%
   rename(iso2 = geo) %>%
   group_by(iso2) %>%
@@ -7601,7 +7602,9 @@ hh_data = read_csv(here("data", "total_private_households.csv")) %>%
   select(-total_private_households)
 
 #3) Eurostat mean expenditures per household income quintile per household and per adult equivalent
-df_expenditure_long = read_csv(here("data",
+df_expenditure_long = read_csv(here("analysis",
+                                    "preprocessing",
+                                    "income-stratified-footprints",
                                     "mean_expenditure_by_quintile_long.csv"),
                                na = ":") %>%
   #filter(year >=2010, geo != "IT") %>%
@@ -7701,8 +7704,8 @@ df_adult_e_p_hh %>%
 
 df_adult_e_p_hh %>%
   filter(iso2 %in% complete_countries, year<=2015, year>=2005) %>%
-  mutate(quint = parse_number(quintile)) %>%
-  write_csv(here("data", "adult_eq_per_household.csv"))
+  mutate(quint = parse_number(quintile)) #%>%
+  #write_csv(here("data", "adult_eq_per_household.csv"))
 
 
 # calculate EU expenditure tiles based on loaded mrio result file and adult equivalents.
@@ -7886,7 +7889,7 @@ df_mapped_result_data = df_mapped_result_2005_data %>%
   bind_rows(df_mapped_result_2015_data)
 
 write_csv(df_mapped_result_data, 
-          here(paste0("data/mrio_results_eu_ntile_mapped_n_", target_eu_ntiles, ".csv")))
+          here(paste0("analysis/data/derived/mrio_results_eu_ntile_mapped_n_", target_eu_ntiles, "_check.csv")))
 
 df_mapped_result_ntiles = 
   df_mapped_result_2005_ntiles %>% mutate(year=2005) %>%
@@ -7896,26 +7899,9 @@ df_mapped_result_ntiles =
 write_csv(df_mapped_result_ntiles, 
           here(paste0("data/eu_ntiles_n_", target_eu_ntiles, ".csv")))
 
-######
-
-knitr::opts_chunk$set(echo = FALSE, message=FALSE)
-
-if (!require("pacman")) install.packages("pacman")
-pacman::p_load(tidyverse,
-               janitor,
-               here,
-               wbstats,
-               ISOcodes,
-               viridis,
-               imputeTS,
-               hrbrthemes,
-               wesanderson,
-               glue)
-
-target_eu_ntiles = 10
-
-source(here("code", "helper_functions.R"))
+###### pxp version
 
+# 1) load MRIO result file
 dat_results_raw = read_rds(here("data", "results_formatted_method1_pxp_pps_hh_no_rent.rds")) %>%
   ungroup() %>%
   mutate(year= strtoi(year)) %>%
@@ -8229,25 +8215,7 @@ df_mapped_result_ntiles =
 write_csv(df_mapped_result_ntiles, 
           here(paste0("data/eu_ntiles_n_", target_eu_ntiles, "_pxp.csv")))
 
-######
-
-knitr::opts_chunk$set(echo = FALSE, message=FALSE)
-
-if (!require("pacman")) install.packages("pacman")
-pacman::p_load(tidyverse,
-               janitor,
-               here,
-               wbstats,
-               ISOcodes,
-               viridis,
-               imputeTS,
-               hrbrthemes,
-               wesanderson,
-               glue)
-
-target_eu_ntiles = 10
-
-source(here("code", "helper_functions.R"))
+###### alternative method, ixi version
 
 # 1) load MRIO result file
 dat_results_raw = read_rds(here("data", "results_formatted_method2_ixi_pps_hh_no_rent.rds")) %>%
-- 
GitLab