diff --git a/analysis/preprocessing/full_code.Rmd b/analysis/preprocessing/full_code.Rmd index 86f41de217845dfbe8ca7aef3cf91023bc802a1d..f28cd43410563ff0ba9006b85bfca1351f75ef9b 100644 --- a/analysis/preprocessing/full_code.Rmd +++ b/analysis/preprocessing/full_code.Rmd @@ -1101,45 +1101,44 @@ HBS: European household budget survey from EUROSTAT, macro-data, from : https:// 2) 'Structure of consumption expenditure by income quintile and COICOP consumption purpose (hbs_str_t223)' -Would be in an 'income-stratified-footprints' preprocessing folder +Direct energy use/emissions from households: +1) For energy, the EUROSTAT data table 'Energy supply and use by NACE Rev. 2 activity' [env_ac_pefasu] at: http://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=env_ac_pefasu [accessed on 03.06.2020]. -1) The 'lfst_hhnhtych' table from EUROSTAT, selecting all available years and total households [accessed on 04.05.2020]. +2) For emissions to air, we download the EUROSTAT data table 'Air emissions accounts by NACE Rev. 2 activity' [env_ac_ainah_r2] at: https://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=env_ac_ainah_r2&lang=en [accessed on 03.06.2020]. -2) Norway is missing from the 'lfst_hhnhtych' EUROSTAT table. We download Norwegian data from the Norwegian statistical office: https://www.ssb.no/en/statbank/table/10986/. We select 'Private households', 'the whole country', no household type selection, all years (2005-2019), and continue with 'Table - Layout 1', then save the table as a 'Tab delimited without heading (csv)' file [accessed on 04.05.2020]. +Trade and Transport margin tables, Taxes less Subsidies tables (National Accounts > Annual National Accounts > Supply and Use Tables > SUT Indicators): https://stats.oecd.org/index.aspx?queryid=84864# + + 1) Trade and transport margins in percentage of final consumption expenditure by households: Export as text file (csv) - customize to include years 2005 to 2015 [accessed on: 15-04-2020] + + 2) Taxes less subsidies on product in percentage of final consumption expenditure by households: Export as text file (csv) - customize to include years 2005 to 2015 [accessed on: 15-04-2020] ```{r income-stratified-footprints, eval = FALSE} -# income-stratified-footprints directory -#data_dir_income_stratified_footprints = paste("/",file.path("data","metab","income-stratified-footprints", fsep=.Platform$file.sep),sep="") +# set data directory for income-stratified-footprint files data_dir_income_stratified_footprints = here("analysis", "preprocessing", "income-stratified-footprints") -data_dir_exiobase = here("analysis", "preprocessing", "EXIOBASE") -################################################### !!!! method 1 - PPS HH - RENT NOT MAPPED TO EXIOBASE !!!! ########################################### +################################################### main paper method #################################################################################### ########################################################################################################################################################## ########################################################################################################################################################## -#### IF YOU WANT THE RESULTS USING PPS PER ADULT EQUIVALENT - FILTER 'MEAN EXPENDITURE BY QUINTILE' BELOW FOR (unit == "PPS_AE") AND MAKE SURE TO UNCOMMENT -#### THE LINE SAVING IT AT THE END (AND COMMENT OUT THE LINE SAVING THE 'PPS HH' VERSION) - for both ixi and pxp Exiobase versions - -## Eurostat Household Budget Survey - -# load 'mean expenditure by quintile' data +# EUROSTAT Household Budget Survey (HBS) +## load 'Mean consumption expenditure by income quintile (hbs_exp_t133)' table hbs_exp_t133 = read_csv(paste0(data_dir_income_stratified_footprints, "/hbs_exp_t133.csv")) -# rename and arrange by country +## rename and arrange by country mean_expenditure_by_quintile = hbs_exp_t133 %>% rename(geo = 3, quintile = "quantile") %>% arrange(geo) -# load 'mean expenditure by quintile and coicop' data +## load 'structure of consumption expenditure by income quintile and COICOP consumption purpose (hbs_str_t223)' table hbs_str_t223 = read_csv(paste0(data_dir_income_stratified_footprints, "/hbs_str_t223.csv")) -# rename and arrange by country +## rename and arrange by country mean_expenditure_by_coicop_sector = hbs_str_t223 %>% rename(geo = 4, quintile = "quantile") %>% arrange(geo) -# create long data set +## create long data set for mean expenditure by quintile table, saving it for use later when creating European expenditure deciles, and keeping both per household and per adult equivalent units mean_expenditure_by_quintile_long = mean_expenditure_by_quintile %>% filter(!(quintile %in% c("UNK","TOTAL"))) %>% filter(!(geo %in% c("EA", @@ -1159,15 +1158,23 @@ mean_expenditure_by_quintile_long = mean_expenditure_by_quintile %>% gather(year,pps,-quintile,-unit,-geo) %>% rename(mean_expenditure = pps) +## write long data set as .csv file to 'data_dir_income_stratified_footprints' - used later in final code chunk for creating European expenditure deciles write_csv(mean_expenditure_by_quintile_long, paste0(data_dir_income_stratified_footprints, "/mean_expenditure_by_quintile_long.csv")) -# create long data sets for both +## create long data set for mean expenditure by quintile table for use in this code chunk, filter for per household mean_expenditure_by_quintile_long = mean_expenditure_by_quintile %>% filter(unit == "PPS_HH") %>% # filter 'mean expenditure by quintile' in PPS per HouseHold filter(!(quintile %in% c("UNK","TOTAL"))) %>% # filter out unknown and total expenditure select(-unit) %>% gather(year,pps,-quintile,-geo) +## create long data set for structure of mean consumption expenditure by quintile table +### here we collapse (sum) the two 'rent' HBS sectors 'CP041' and 'CP042' to create a +### single 'rent' sector. We make some manual adjustments where one coicop level 2 consumption +### category is missing data, using the total coicop level 1 expenditure and expenditure in the +### other coicop level 2 categories to calculate the difference. These may not be relevant for +### future available updates of the EUROSTAT HBS if they have been corrected. In that case, comment out the +### mutations at the end of this code. mean_expenditure_by_coicop_sector_long = mean_expenditure_by_coicop_sector %>% filter(!(quintile %in% c("UNK","TOTAL"))) %>% # filter out unknown and total expenditure select(-unit) %>% @@ -1178,9 +1185,9 @@ mean_expenditure_by_coicop_sector_long = mean_expenditure_by_coicop_sector %>% mutate(pm = parse_number(pm), pm = as.numeric(pm)) %>% summarise(pm = sum(pm, na.rm = TRUE)) %>% - ungroup() %>% + ungroup() %>% mutate(pm = ifelse(geo == "DE" & year == 2005 & quintile == "QUINTILE1" & - coicop == "CP072", 92-21-14,pm)) %>% + coicop == "CP072", 92-21-14,pm)) %>% mutate(pm = ifelse(geo == "DE" & year == 2005 & quintile == "QUINTILE2" & coicop == "CP072", 108-22-12,pm)) %>% mutate(pm = ifelse(geo == "DE" & year == 2005 & quintile == "QUINTILE3" & @@ -1209,46 +1216,48 @@ mean_expenditure_by_coicop_sector_long = mean_expenditure_by_coicop_sector %>% coicop == "CP044", 326-10-61-228,pm)) %>% mutate(pm = ifelse(geo == "DE" & year == 2015 & quintile == "QUINTILE5" & coicop == "CP044", 280-9-49-195,pm)) -## In the code above, I collapse (sum) the two 'rent' HBS sectors 'CP041' and 'CP042' to create a -## single 'rent' sector so as to allocate all rent to 'Real-estate services' in Exiobase. - -# join the HBS expenditure tables together +# join the two long HBS tables together join_expenditures = mean_expenditure_by_coicop_sector_long %>% left_join(mean_expenditure_by_quintile_long, by = c("geo","quintile","year")) %>% mutate(pps = as.numeric(pps), pm = as.numeric(pm), pps_coicop = pm*(pps/1000)) +################################################### main paper method, EXIOBASE industry-by-industry version ############################################# ########################################################################################################################################################## +# EXIOBASE industry-by-industry version -################################################### !!!! method 1 - IXI version - PPS HH NO RENT !!!! #################################################### -########################################################################################################################################################## -########################################################################################################################################################## - -## Exiobase - ixi version - +## set study years years_exb_ixi = c(2005,2010,2015) +## create NULL dataframe for dis-aggregated final demand disaggregated_final_demand = NULL +## create NULL dataframe for 'total intensity vectors' TIVs = NULL +## create NULL dataframe for domestic 'total intensity vectors' domestic_TIVs = NULL +## create NULL dataframe for rest-of-Europe 'total intensity vectors' europe_TIVs = NULL +## create NULL dataframe for national footprints national_fp = NULL +## create NULL dataframe for national territorial energy use/emissions national_territorial = NULL +## 'for' loop which populates the above NULL dataframes for (i in years_exb_ixi){ + year_current = i + ## EXIOBASE final demand table without labels (.csv file) Exiobase_FD = read.csv(paste0(data_dir_exiobase, "/IOT_",year_current,"_ixi/FD_",year_current,"_ixi.csv"))[,-1] - # select household final demand vectors for study countries - + ## select household final demand vectors for study countries AT = Exiobase_FD[,1] BE = Exiobase_FD[,8] BG = Exiobase_FD[,15] @@ -1282,12 +1291,10 @@ for (i in years_exb_ixi){ Eurostat_countries = cbind(AT,BE,BG,CY,CZ,DE,DK,EE,EL,ES,FI,FR,HR,HU,IE,IT,LT,LU,LV,MT,NL,NO,PL,PT,RO,SE,SI,SK,TR,UK) - # labels - + ## read in EXIOBASE production sector labels written and saved in previous code chunk Exiobase_T_labels = read.csv(paste0(data_dir_income_stratified_footprints, "/Exiobase_T_labels_ixi_w_coicop_mapping.csv")) %>% mutate(V1 = dplyr::recode(V1,"GR" = "EL","GB" = "UK")) - # hh fd with production sector labels hh_fd_with_production_sector_labels = cbind(Exiobase_T_labels,Eurostat_countries) %>% rename(geo = V1, sector = V2) @@ -7483,6 +7490,10 @@ write_rds(results_formatted_with_direct_FD_fp, paste0(data_dir_income_stratified - need to download EUROSTAT households and Norway households +1) The 'lfst_hhnhtych' table from EUROSTAT, selecting all available years and total households [accessed on 04.05.2020]. + +2) Norway is missing from the 'lfst_hhnhtych' EUROSTAT table. We download Norwegian data from the Norwegian statistical office: https://www.ssb.no/en/statbank/table/10986/. We select 'Private households', 'the whole country', no household type selection, all years (2005-2019), and continue with 'Table - Layout 1', then save the table as a 'Tab delimited without heading (csv)' file [accessed on 04.05.2020]. + ```{r european-expenditure-deciles, eval = FALSE} # set target number of quantiles