---
title: "On the numerical inevitability of socialism"
author:
  - Ingram S. Jaccard:
      email: jaccard@pik-potsdam.de
      institute: [PIK]
      correspondence: false
  - Peter-Paul Pichler:
      email: pichler@pik-potsdam.de
      institute: [PIK]
      correspondence: false
  - Johannes Többen:
      email: toebben@pik-potsdam.de
      institute: [PIK]
      correspondence: false
  - Helga Weisz:
      email: weisz@pik-potsdam.de
      institute: [PIK, HU]
      correspondence: false
institute:
  - PIK: Social Metabolism and Impacts, Potsdam Institute for Climate Impact Research, Member of the Leibniz Association, PO Box 60 12 03, Potsdam, 14412, Germany
  - HU: Department of Cultural History & Theory and Department of Social Sciences, Humboldt University Berlin, Unter den Linden 6, Berlin, 10117, Germany
output: 
    bookdown::word_document2:
      fig_caption: yes
      reference_docx: "../templates/template.docx" # Insert path for the DOCX file
      pandoc_args:
      - --lua-filter=../templates/scholarly-metadata.lua
      - --lua-filter=../templates/author-info-blocks.lua
      - --lua-filter=../templates/pagebreak.lua
bibliography: references.bib
csl: "../templates/vancouver.csl" # Insert path for the bib-style
keywords: |
  keyword 1; keyword 2; keyword 3
highlights: |
  These are the highlights. 
abstract: | 
---

<!-- This is the format for text comments that will be ignored during renderings. Do not put R code in these comments because it will not be ignored. -->

<!-- With the following code you can access and display values from the yaml header above. -->

Keywords: `r rmarkdown::metadata$keywords`

Highlights: `r rmarkdown::metadata$highlights`

Abstract: `r rmarkdown::metadata$abstract`

<!-- The following code chunk defines some general settings how code chunks should behave. -->

```{r setup, echo = FALSE, include = FALSE, message = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  echo = FALSE,
  comment = "#>",
  fig.path = "../figures/",
  dpi = 300
)

if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse,
               janitor,
               here,
               wbstats,
               ISOcodes,
               viridis,
               hrbrthemes,
               wesanderson,
               glue,
               ggridges,
               patchwork,
               kableExtra,
               readxl,
               flextable)

pal <- wes_palette("Cavalcanti1", 5, type = "discrete")
extrafont::loadfonts()

```

```{r libraries}

library(here)
```

```{r functions}

source(here("analysis", "R", "wrangler_functions.R"))

```

```{r load-data, include=FALSE}
# load data wrangling functions
source(here("analysis", "R", "wrangler_functions.R"))

## load result data for EU deciles
eu_q_count = 10

# summary countries aggregated by country quintiles and eu ntile
dat_country_summary_by_cquint_and_euntile = get_country_summary_by_cquint_and_euntile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "iso2", "quint", "eu_q_rank")
pdat_country_summary_by_cquint_and_euntile =
  pivot_results_longer_adorn(dat_country_summary_by_cquint_and_euntile, cols_ex)

# summary of countries by EU quantile without sectoral resolution
dat_country_summary_by_eu_ntile = get_country_summary_by_eu_ntile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "iso2", "eu_q_rank")
pdat_country_summary_by_eu_ntile = 
  pivot_results_longer_adorn(dat_country_summary_by_eu_ntile, cols_ex)

# summary of countries by country quintile with aggregate sectoral resolution
dat_sector_summary_by_country_quintile = get_sector_summary_by_country_quintile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "iso2", "quint", "eu_q_rank", "sector_agg_id")
pdat_sector_summary_by_country_quintile =
  pivot_results_longer_adorn(dat_sector_summary_by_country_quintile, cols_ex)

# summary of eu ntile with aggregate sectoral resolution
dat_sector_summary_by_eu_ntile = get_sector_summary_by_eu_ntile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "eu_q_rank", "sector_agg_id")
pdat_sector_summary_by_eu_ntile =
  pivot_results_longer_adorn(dat_sector_summary_by_eu_ntile, cols_ex)


```

<!-- The actual document text starts here: -->

# Introduction

Decarbonizing the energy system in accordance with the Paris Accord requires a deep transformation of both the supply and the demand side (ref). On both sides, however, necessary transformation is restricted by different factors. On the supply side, there exist economic and physical upper limits of how much energy can be provided from renewable sources on the one hand, and how much CO2 removal infrastructure is used to compensate for remaining emissions from fossil fuels on the other. On the demand side [@creutzig_towards_2018], by contrast, there are lower limits to how much energy is minimally required for a decent life [@grubler_low_2018 @millward-hopkins_providing_2020], depending on different assumptions about the available infrastructure of energy services, as well as the prevalent social ideas about what constitutes a good life (ref). Maximum possible energy supply and minimum necessary energy demand describe the space in which the simultaneous achievement of climate targets and a decent living for all is possible and, at the same time, restricts the distribution of available energy services among the population. If this dual objective is taken seriously in European climate policy, then there are practical limits to how unequal the society of the future can be, which go beyond the purely political. In fact, a limited energy supply creates an obvious, if rarely acknowledged, zero-sum game where energetic over-consumption by some has to be compensated by less consumption by others. 

The European Green Deal already recognizes that inequalities in incomes, energy consumption and greenhouse gas emissions lead to different responsibilities and capacities in achieving the emission savings targets (ref), and includes proposals to increase equity and political acceptance [*which are?*]. 

The average energy footprint of EU citizens was X GJ per capita in 2011 [@oswald_large_2020] and the carbon footprint 8.2 tonnes CO2eq per capita in 2007 [@ivanova_environmental_2016]. However, the differences in average energy and carbon footprints are large within and between different regions in the EU. Energy footprints ranged from X to Y GJ per capita in 2011 [@oswald_large_2020] and carbon footprints from below 2.5 tonnes CO2eq per capita to 55 tonnes CO2eq per capita in 2010 [@ivanova_unequal_2020]. Depending on the assumptions of different global mitigation scenarios, the average footprints need to be reduced to between 15.7 and 100 GJ per capita [@grubler_low_2018 @millward-hopkins_providing_2020] or 0.7 and 2.1 tCO2eq per capita [@akenji_1.5-degree_2019] by 2050, respectively.

In this paper, we assess under what conditions European energy inequality is compatible with the achievement of global climate goals and a decent standard of living, taking both inequality within and between European countries into account. To this end, we first construct energy and carbon footprints for harmonized European expenditure deciles for the year 2015, combining data from EUROSTAT's Household Budget Survey (HBS) with the Environmentally-Extended Multi-Regional Input-Output (EE-MRIO) model EXIOBASE. After exploring the distribution of energy and carbon intensities across European expenditure deciles and consumption purposes, we compare this current structure to an empirical per sector best technology counterfactual. We find that even under best currently available technology per sector, X% of European households ... [*one sentence on the main finding from comparing current vs. best technology*]. [*to my opinion, this is too detailed information for an introduction - from 'EUROSTAT's Household Budget Survey.....' to here*]. Finally, we relate the energy demands under best technology[*?*] to available supply across different global 1.5°C scenarios from the literature and examine how the energy inequality across households must change, in order to achieve a decent life for all. We find that ... [*one sentence on the main finding from 1.5 degree scenarios*]. Based on our findings, we discuss implications for energy use in different expenditure deciles as well as for policy. 

# Materials and methods

In this paper, we:

1) Decompose *national* household final demand expenditure in the EE-MRIO model EXIOBASE (version3, industry-by-industry) [@stadler_exiobase_2018], by national *income* quintile, using European household budget survey (HBS) macro-data from EUROSTAT [@eurostat_database_nodate]. 

2) Use this income-decomposed *national* household final demand expenditure to calculate *national* household energy and carbon footprints also decomposed by national *income* quintile. 

3) Finally, we take the mean expenditure of each national income quintile, and distribute the national income quintiles from lowest to highest mean expenditure, constructing European expenditure deciles. Our analysis in this paper focuses on these results: household final demand expenditure, the household energy footprint, and the household carbon footprint decomposed by European expenditure decile.  

## Income-stratified national household final demand expenditure

The first step was decomposing *national* household final demand expenditure in EXIOBASE [@stadler_exiobase_2018] by national *income* quintile, using the European household budget survey (HBS) from EUROSTAT [@eurostat_database_nodate]. The EUROSTAT HBS publishes national data on mean consumption expenditure by income quintile (in purchasing power standards (PPS)) and the structure of consumption expenditure by income quintile and COICOP consumption category. We mapped the EXIOBASE sectors to one of the COICOP consumption categories (our mapping can be found in the SI), and used the relative shares of each COICOP consumption category between the income quintiles in the HBS to decompose the EXIOBASE national household final demand expenditure per sector by income quintile as well. 

## Income-stratified national household environmental footprints

We then multiplied this income-stratified EXIOBASE national household final demand expenditure by 'direct and indirect supply chain' energy use and carbon intensities per EXIOBASE sector, calculated in EXIOBASE using standard input-output calculations, to estimate national household energy and carbon footprints stratified by income quintile. We used EXIOBASE as the EE-MRIO for this study because of its European focus, with nearly all countries in the EUROSTAT HBS also found as stand-alone countries in EXIOBASE (see SI - table 5), its detailed satellite extension data, and its year coverage (specifically version3, industry-by-industry). 

### Environmental extensions used

The energy footprint is calculated using the 'gross total energy use' energy extension in EXIOBASE, which converts final energy consumption in the IEA energy balance data from the territorial to residence principle following SEEA energy accounting [@stadler_exiobase_2018]. The carbon footprint includes CO2, CH4, N2O, SF6, HFCs and PFCs, from combustion, non-combustion, agriculture and waste, but not land-use change. For both environmental footprints, direct energy use and carbon emissions from households is included, with the total split between shelter, transport and manufactured goods using further data from EUROSTAT on this split.

## European expenditure deciles

Finally, we aggregated the data of 28 European countries with 5 income groups each into 10 European expenditure groups, to decompose the total European household energy and carbon footprint by European expenditure decile, ranking each national income group according to their mean consumption expenditure in PPS. We call these European expenditure deciles, although only countries with EUROSTAT HBS data from 2005 to 2015 are included, which excludes Italy and Luxembourg, but includes the UK, Norway and Turkey. 

## Units of analysis

Our unit of analysis through the study is households per adult equivalent unit. This is the unit of analysis used in the EUROSTAT HBS when normalizing household size between income groups and countries, and we aimed to keep the results of our study within this framework: the first adult in the household is given a weight of 1.0, each adult thereafter 0.5, and each child 0.3 [@eurostat_description_2016]. 

When we situate our results within decarbonisation scenarios, we adjust the total per capita results from the scenarios, to household per adult equivalent in order to better compare with our environmental footprint estimates. Data on decarbonization scenarios, especially final energy use, is from the IIASA scenario database [@riahi_shared_2017 @gea_gea_nodate], and work by Grubler et al. (2018) [@grubler_low_2018] and Millward-Hopkins et al. (2020) [@millward-hopkins_providing_2020]. 

For example, we adjust a total final energy use of 53 GJ per capita from the LED scenario (Grubler et al. (2018) [@grubler_low_2018]), first by the household share of the total European energy footprint in 2015 (around 0.62, calculated in EXIOBASE), and then the share of total adult equivalents in the total European population in 2015 (also around 0.62, calculated using the EUROSTAT HBS, number of households per country, and population data per country): a total final energy use of 53 GJ/capita is therefore adjusted to a household final energy use of 53 GJ/adult equivalent in Europe ((53 total GJ/capita * 0.62 household share of total footprint)/0.62 adult equivalent share of population = 53 household GJ/adult equivalent). 

As inequality measure through the study, we divide the value in the top European expenditure decile by that of the bottom European expenditure decile, a 10:10 ratio. For example, in expenditure, a 10:10 ratio of 5 means that adult equivalents in the top decile spend 5 times more on average than those in the bottom decile. All data and procedures are described in detail in the supplementary information (SI), and the whole analysis was performed in RStudio [@r_core_team_r:_2020 @wickham_welcome_2019].

# Results

## Environmental footprints are less unequal than expenditure levels

```{r ntiles-total}

p1 = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_fd_me") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name)) %>%
  ggplot(aes(x=eu_ntile_name, y=value)) +
    geom_col(position = position_dodge(), fill=pal[1]) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Expenditure (trn€)") +
    theme(axis.text.x = element_text(angle = 90))

p2 = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_energy_use_tj") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name)) %>%
  ggplot(aes(x=eu_ntile_name, y=value)) +
    geom_col(position = position_dodge(), fill=pal[1]) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Energy footprint (EJ)") +
    theme(axis.text.x = element_text(angle = 90))

p3 = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_co2eq_kg") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000000001,
            eu_ntile_name = first(eu_ntile_name)) %>%
  ggplot(aes(x=eu_ntile_name, y=value)) +
    geom_col(position = position_dodge(), fill=pal[1]) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Carbon footprint (MtCO2eq)") +
    theme(axis.text.x = element_text(angle = 90))


p_top = p1 + p2 + p3

```

```{r ntiles-intensity-violin}


p1 = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  ggplot(aes(x=factor(eu_q_rank), y=pe_co2eq_kg)) +
  geom_violin(aes(weight=total_fd_me), fill=pal[1], color=pal[1], alpha=0.5) +
  geom_point( alpha=0.3) +
  geom_segment(data=dat_country_summary_by_eu_ntile %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(pe_co2eq_kg = weighted.mean(pe_co2eq_kg,total_fd_me)),
               aes(y=pe_co2eq_kg, yend=pe_co2eq_kg, x=eu_q_rank-0.3, xend=eu_q_rank+0.3), size=1.5) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Carbon intensity per expenditure (kgCO2eq/€)") +
    theme(axis.text.x = element_text(angle = 90))

p2 = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  ggplot(aes(x=factor(eu_q_rank), y=pe_energy_use_mj)) +
  geom_violin(aes(weight=total_fd_me), fill=pal[1], color=pal[1], alpha=0.5) +
  geom_point( alpha=0.3) +
  geom_segment(data=dat_country_summary_by_eu_ntile %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(pe_energy_use_mj = weighted.mean(pe_energy_use_mj,total_fd_me)),
               aes(y=pe_energy_use_mj, yend=pe_energy_use_mj, x=eu_q_rank-0.3, xend=eu_q_rank+0.3), size=1.5) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Energy intensity per expenditure (MJ/€)") +
    theme(axis.text.x = element_text(angle = 90))

dat3 = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  mutate(intensity_e_c = total_co2eq_kg*0.001/total_energy_use_tj)

p3 = dat3 %>%
  ggplot(aes(x=factor(eu_q_rank), y=intensity_e_c)) +
  geom_violin(aes(weight=total_energy_use_tj), fill=pal[1], color=pal[1], alpha=0.5) +
  geom_point( alpha=0.3) +
  geom_segment(data=dat3 %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(intensity_e_c = weighted.mean(intensity_e_c,total_energy_use_tj)),
               aes(y=intensity_e_c, yend=intensity_e_c, x=eu_q_rank-0.3, xend=eu_q_rank+0.3), size=1.5) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Carbon intensity per energy (gCO2eq/TJ)") +
    theme(axis.text.x = element_text(angle = 90)) 


p_bottom = p2 + p1 + p3

#p3 & theme(plot.margin =  margin(1, 1, 1, 1, "mm"))
```

```{r , fig.width=12, fig.height=8}

a = p_top / p_bottom + plot_annotation(tag_levels = 'a') +
  plot_layout(guides = 'collect')  & 
  theme(plot.margin = unit(c(0.25,0.25,0.25,0.25), "cm"),
        legend.position = 'bottom',
        axis.title.y = element_text(size=13, hjust = 0.5),
        axis.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 12),
        legend.text = element_text(size=12),
        legend.title = element_text(size=13))

ggsave(here("analysis", "figures", "figure1.pdf"), device=cairo_pdf)

```

```{r values-in-text1}

# values in text

## inequality
exp = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_fd_me") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name))

exp_10_10 = round((exp %>% filter(eu_q_rank == 10))$value/(exp %>% filter(eu_q_rank == 1))$value,digits = 1)

energy = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_energy_use_tj") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name))

energy_10_10 = round((energy %>% filter(eu_q_rank == 10))$value/(energy %>% filter(eu_q_rank == 1))$value,digits = 1)

co2eq = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_co2eq_kg") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000000001,
            eu_ntile_name = first(eu_ntile_name))

co2eq_10_10 = round((co2eq %>% filter(eu_q_rank == 10))$value/(co2eq %>% filter(eu_q_rank == 1))$value,digits = 1)

## total per decile

exp_bottom_decile = round((exp %>% filter(eu_q_rank == 1))$value, digits = 1)

exp_top_decile = round((exp %>% filter(eu_q_rank == 10))$value, digits = 1)

energy_bottom_decile = round((energy %>% filter(eu_q_rank == 1))$value, digits = 1)

energy_top_decile = round((energy %>% filter(eu_q_rank == 10))$value, digits = 1)

co2eq_bottom_decile = round((co2eq %>% filter(eu_q_rank == 1))$value, digits = 1)

co2eq_top_decile = round((co2eq %>% filter(eu_q_rank == 10))$value, digits = 1)


## per adult equivalent per decile

aeu = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015,
         indicator == "total_adult_eq") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value),
            eu_ntile_name = first(eu_ntile_name)) 

exp_pae = exp %>%
  rename(total_fd_me = value) %>%
  left_join(aeu, by = c("eu_q_rank", "eu_ntile_name")) %>%
  mutate(pae_fd_e = (total_fd_me/value)*1000000000000)

fd_pae_bottom_decile = round((exp_pae %>% filter(eu_q_rank == 1))$pae_fd_e, digits = 0)

fd_pae_top_decile = round((exp_pae %>% filter(eu_q_rank == 10))$pae_fd_e, digits = 0)

energy_pae = energy %>%
  rename(total_energy_use_tj = value) %>%
  left_join(aeu, by = c("eu_q_rank", "eu_ntile_name")) %>%
  mutate(pae_energy_use_gj = (total_energy_use_tj/value)*1000000000)

energy_pae_bottom_decile = round((energy_pae %>% filter(eu_q_rank == 1))$pae_energy_use_gj, digits = 1)

energy_pae_top_decile = round((energy_pae %>% filter(eu_q_rank == 10))$pae_energy_use_gj, digits = 1)

co2eq_pae = co2eq %>%
  rename(total_co2eq_kg = value) %>%
  left_join(aeu, by = c("eu_q_rank", "eu_ntile_name")) %>%
  mutate(pae_co2eq_t = (total_co2eq_kg/value)*1000000)

co2eq_pae_bottom_decile = round((co2eq_pae %>% filter(eu_q_rank == 1))$pae_co2eq_t, digits = 1)

co2eq_pae_top_decile = round((co2eq_pae %>% filter(eu_q_rank == 10))$pae_co2eq_t, digits = 1)


## intensities

mean_energy_intens = dat_country_summary_by_eu_ntile %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(pe_energy_use_mj = weighted.mean(pe_energy_use_mj,total_fd_me))

mean_energy_intens_bottom_decile = round((mean_energy_intens %>% filter(eu_q_rank == 1))$pe_energy_use_mj, digits = 1)

mean_energy_intens_top_decile = round((mean_energy_intens %>% filter(eu_q_rank == 10))$pe_energy_use_mj, digits = 1)

mean_co2eq_of_energy_intens = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  mutate(intensity_e_c = total_co2eq_kg*0.001/total_energy_use_tj) %>%
  group_by(eu_q_rank) %>%
  summarise(intensity_e_c = weighted.mean(intensity_e_c,total_energy_use_tj))

mean_co2eq_of_energy_intens_bottom_decile = round((mean_co2eq_of_energy_intens %>% filter(eu_q_rank == 1))$intensity_e_c, digits = 1)

mean_co2eq_of_energy_intens_top_decile = round((mean_co2eq_of_energy_intens %>% filter(eu_q_rank == 10))$intensity_e_c, digits = 1)

```

Consumption-based indicators such as the energy and carbon footprint of households are largely determined by their spending levels. An inequality of household expenditures in a population therefore implies an inequality of their environmental footprints. Figures 1a-c show European households by decile of expenditure and their associated footprints for energy and carbon in 2015. The figures show that increasing expenditure generally translated into larger footprints, but that the inequality decreased from expenditure to energy to carbon, with 10:10 ratios (the top decile divided by the bottom decile) of `r exp_10_10`, `r energy_10_10` and `r co2eq_10_10`, respectively. Total expenditure ranged from `r exp_bottom_decile` trn€ to `r exp_top_decile` trn€ (or `r fd_pae_bottom_decile`€ to `r fd_pae_top_decile`€ per adult equivalent) across bottom and top decile, the energy footprint from `r energy_bottom_decile` EJ to `r energy_top_decile` EJ (or `r energy_pae_bottom_decile` GJ/ae to `r energy_pae_top_decile` GJ/ae), and the carbon footprint from `r co2eq_bottom_decile` MtCO2eq to `r co2eq_top_decile` MtCO2eq (or `r co2eq_pae_bottom_decile` tCO2eq/ae to `r co2eq_pae_top_decile` tCO2eq/ae). The reason for this is evident from figures 1d-f. Both the energy intensity of consumption, measured as energy use per € expenditure (d), and the carbon intensity of energy, measured as carbon per unit of energy use (f), gradually decrease from bottom to top expenditure decile. The weighted average energy intensity of consumption decreased from `r mean_energy_intens_bottom_decile` MJ/€ in the bottom decile to less than half (`r mean_energy_intens_top_decile` MJ/€) in the top decile. Additionally, the carbon intensity of energy was also higher in the bottom decile (`r mean_co2eq_of_energy_intens_bottom_decile` gCO2eq/TJ) compared to the top decile (`r mean_co2eq_of_energy_intens_top_decile` gCO2eq/TJ). There is a clear trend of decreasing intensities across expenditure deciles even though the variance in the lower deciles is much higher. The carbon intensity of consumption (figure 1e) combines the effects of the intensities of 1d and 1f. The higher carbon intensity of energy is likely due to a larger share of emission intensive energy carriers in the energy system. The decreasing energy intensity of consumption is due to either inefficient energy technologies or energy subsidies in lower-income areas in Europe.

```{r figure1, out.width="98%", fig.cap="Household expenditure and environmental footprints and intensities across European expenditure deciles. Total expenditures (a), energy footprint (b), and carbon footprint (c) per decile. Energy intensity of consumption as energy footprint per expenditure (d), carbon intensity of consumption as carbon footprint per expenditure (e), and carbon intensity of energy as carbon footprint per energy footprint (f)."}
knitr::include_graphics(here::here("analysis", "figures", "figure1.pdf"))
```

Figures 1d-e show that energy and carbon intensities of consumption are particularly high in the lower four deciles, while the higher deciles do not show large differences in weighted average energy and carbon intensity. The different intensities of household consumption across European expenditure deciles can be attributed to a combination of two plausible causes: first, if the composition of consumption baskets systematically differs according to the level of household expenditure. Second, if energy and carbon intensity within individual consumption sectors systematically differs according to the level of household expenditure.

```{r , fig.width=8, fig.height=2}

pdat_basket = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  group_by(eu_q_rank) %>%
  mutate(value = total_fd_me/sum(total_fd_me)*100) %>%
  select(five_sectors, eu_q_rank, 
         value) %>%
  mutate(indicator = "Expenditure share (%)")

pdat_int_co2eq = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  mutate(value = (total_co2eq_kg)/(total_fd_me*1000000)) %>%
  select(five_sectors, eu_q_rank, 
         value) %>%
  mutate(indicator = "Carbon intensity (kgCO2eq/€)")

pdat_int_energy = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  mutate(value = (total_energy_use_tj)/(total_fd_me)) %>%
  select(five_sectors, eu_q_rank,
         value) %>%
  mutate(indicator = "Energy intensity (MJ/€)")

library(viridis)
pdat = pdat_int_co2eq %>%
  bind_rows(pdat_int_energy) %>%
  bind_rows(pdat_basket) 

pdat$facet = factor(pdat$indicator, levels = c("Expenditure share (%)", "Energy intensity (MJ/€)", "Carbon intensity (kgCO2eq/€)"))

a = ggplot(pdat, aes(x=value, y=five_sectors, color=eu_q_rank)) +
  #geom_point(shape=18, alpha=0.75) +
  geom_text(label="I", alpha=0.75, fontface="bold") +
  scale_color_viridis(option = "A", end = 0.8,
                      direction = -1, 
                      breaks = c(1, 5, 10), 
                      name="European decile") +
  facet_wrap(~facet, scales="free_x") +
  theme_minimal() +
  labs(x="", y="")+
  theme(text=element_text(size=13, family="Liberation Sans Narrow"))

ggsave(here("analysis", "figures", "figure2.pdf"), device=cairo_pdf)
```

```{r figure2, out.width="100%", fig.cap="Sectoral expenditure shares and carbon intensities of European expenditure deciles. Share of expenditure per final demand sector of total spending per decile in percent (a) and carbon intensity per final demand sector in kgCO2eq/€. Our 'services' category includes the EXIOBASE production sector 'real estate services'."}
knitr::include_graphics(here::here("analysis", "figures", "figure2.pdf"))
```

```{r values-in-text2}

exp_share_shelter_bottom_decile = round((pdat_basket %>% filter(eu_q_rank == 1, five_sectors == "shelter"))$value, digits = 1)

exp_share_shelter_top_decile = round((pdat_basket %>% filter(eu_q_rank == 10, five_sectors == "shelter"))$value, digits = 1)

int_co2eq_shelter_bottom_decile = round((pdat_int_co2eq %>% filter(eu_q_rank == 1, five_sectors == "shelter"))$value, digits = 1)

int_co2eq_shelter_top_decile = round((pdat_int_co2eq %>% filter(eu_q_rank == 10, five_sectors == "shelter"))$value, digits = 1)

exp_share_services_bottom_decile = round((pdat_basket %>% filter(eu_q_rank == 1, five_sectors == "services"))$value, digits = 1)

exp_share_services_top_decile = round((pdat_basket %>% filter(eu_q_rank == 10, five_sectors == "services"))$value, digits = 1)

```

Our results show that both of these factors play a role \@ref(fig:figure2). Lower-income households, on average, spend larger shares of their expenditure in the shelter sector. The bottom and top deciles spend an average of `r exp_share_shelter_bottom_decile`% and `r exp_share_shelter_top_decile`% of their household expenditure on shelter, respectively (this refers to environmental-footprint-relevant shelter expenditure. Our aggregated 'shelter' sector does not include rent. We have included the EXIOBASE production sector 'real estate services', which includes rent and other activities, in our aggregated 'services' sector, not the aggregated 'shelter' sector - see SI Table 4). Overall, with increasing expenditure decile, the shares of transport and services expenditures increase and the shares of shelter, food and manufactured goods decrease. At the same time, shelter is by far the most carbon intensive sector with the highest variance between expenditure deciles. In our sample, the intensity of all sectors decreases with expenditure level but the shelter sector stands out with a carbon intensity of consumption more than 3 times higher in the bottom decile (`r int_co2eq_shelter_bottom_decile` kgCO2eq/€) than in the top decile (`r int_co2eq_shelter_top_decile` kgCO2eq/€). Households in the top decile spend about `r exp_share_services_top_decile`% in the service sector, which has the lowest carbon intensity, compared to `r exp_share_services_bottom_decile`% in the bottom decile. Single country studies using EE-MRIO models with national resolution can pick up on differences in consumption baskets, but due to the homogeneous technology assumption in EE-MRIOs, cannot represent differences in technology between expenditure deciles.

The tendency for energy and carbon intensity to decrease with increasing affluence can be observed at the global level (ref) between countries and also applies within Europe [@sommer_carbon_2017]. In some of the Eastern European countries, between 80% and 100% of the population belong to the four lowest European expenditure deciles. This compares to less than 20% of the population in the higher-income European countries (Scandinavia, Germany, France, Austria, the Netherlands, Belgium, the UK, and Ireland). Note here that our analysis is based on average expenditure data from five income groups at the national level. This aggregation cuts off the lower and higher ends of the respective national expenditure distributions (see SI - Supplementary Note and Map).

The high intensities in the bottom four European expenditure deciles can be attributed in large part to more inefficient and dirtier domestic energy supplies for heating and electricity generation in Poland, Bulgaria, the Czech Republic, and Romania. Poland alone was responsible for about 40% of total coal combustion for heat production in Europe in 2015 [@eurostat_eurostat_nodate-2], and had a higher average intensity of carbon per MJ of heat delivered than both Europe and the world [@werner_international_2017]. These differences in energy and carbon intensities in basic needs sectors (especially shelter) account for the smaller inequality between expenditure deciles, in terms of environmental footprints compared to raw expenditures. [*do we need to mention subsidies also?*]

[*The consumption basket aspect has been extensively studied and mostly found to be intuitively true. This is a line of inquiry we do not currently pursue but I just remembered the analysis we did on this which is actually quite interesting: This common sense knowledge could be challenged because it is true mostly in western countries with high demand for heating and cooling and mobility both mostly fossil based and subsidized. In this case, necessities especially shelter (maybe and car based mobility (accessible to most)) have a higher intensity compared to "luxury spending" ie the average intensity of the international supply chain for manufactured goods etc.. It is not true in rich countries with high renewable energy shares (e.g. Norway) where the domestic energy system is more resource efficient than the international supply chain. It is possibly also not true in countries with low heating/cooling demand. We may want to check if that flips after applying the best technology transformation.*]

## Inequality across final consumption sectors

```{r , fig.width=8, fig.height=5}

pdat = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  select(five_sectors, eu_q_rank, contains("pae_co2eq"), contains("pae_energy")) %>%
  pivot_longer(cols=-c(five_sectors, eu_q_rank), names_to="indicator", values_to="value") %>%
  mutate(indicator_type = if_else(str_detect(indicator, "co2eq"), 
                                  "tCO2eq per adult eq", 
                                  "Energy GJ per adult eq")) %>%
  filter(indicator != "pae_co2eq_t", 
         indicator != "pae_energy_use_gj")
  
  
pal <- wes_palette("Zissou1", 4, type = "discrete")
pal = pal[c(2,1,3,4)]
  
p1 = ggplot(pdat %>% filter(indicator_type == "tCO2eq per adult eq"), 
       aes(x=(eu_q_rank), y=value, fill=indicator)) +
  geom_col(position = position_stack()) +
  facet_wrap(~five_sectors, ncol = 5) +
  scale_fill_manual(values = pal, name="Location", labels=c("Direct", "Domestic", "Europe", "non-Europe")) +
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10), 
                     labels = c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10")) +
  #theme_ipsum() +
  theme_minimal() +
  theme(text=element_text(family="Liberation Sans Narrow")) +
  labs(x="", y="Carbon footprint tCO2eq per adult eq") +
  theme(legend.position = "bottom", 
          axis.text.x = element_text(angle = 90, size = 12),
          axis.text.y = element_text(size = 12),
          strip.text = element_text(size = 12),
          axis.title.y = element_text(size = 10))


p2 = ggplot(pdat %>% filter(indicator_type == "Energy GJ per adult eq"), 
       aes(x=(eu_q_rank), y=value, fill=indicator)) +
  geom_col(position = position_stack()) +
  facet_wrap(~five_sectors, ncol = 5) +
  scale_fill_manual(values = pal, name="Location", labels=c("Direct", "Domestic", "Europe", "non-Europe")) +
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10), 
                     labels = c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10")) +
  #theme_ipsum() +
  theme_minimal() +
  theme(text=element_text(family="Liberation Sans Narrow")) +
  labs(x="", y="Energy footprint GJ per adult eq") +
  theme(legend.position = "bottom", 
          axis.text.x = element_text(angle = 90, size = 12),
          axis.text.y = element_text(size = 12),
          strip.text = element_text(size = 12),
          axis.title.y = element_text(size = 10))

a = p1 / p2 + plot_layout(guides = "collect") & theme(legend.position = 'bottom', 
                                                  plot.margin =  margin(1, 1, 1, 1, "mm"),
                                                  panel.spacing = unit(c(1, 1, 1, 1), "mm"))


hm = pdat %>% filter(indicator_type == "Energy GJ per adult eq") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value))

ggsave(here("analysis", "figures", "figure3.pdf"))
```

```{r values-in-text3}

co2eq_per_sector = pdat %>%
  filter(indicator_type == "tCO2eq per adult eq") %>%
  group_by(five_sectors, eu_q_rank) %>%
  summarise(value = sum(value))

transport_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "transport"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "transport"))$value,digits = 0)

man_goods_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "manufactured goods"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "manufactured goods"))$value,digits = 0)

services_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "services"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "services"))$value,digits = 1)

food_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "food"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "food"))$value,digits = 1)

energy_per_sector = pdat %>%
  filter(indicator_type == "Energy GJ per adult eq") %>%
  group_by(five_sectors, eu_q_rank) %>%
  summarise(value = sum(value))

transport_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "transport"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "transport"))$value,digits = 0)

man_goods_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "manufactured goods"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "manufactured goods"))$value,digits = 0)

services_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "services"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "services"))$value,digits = 1)

food_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "food"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "food"))$value,digits = 1)

```

In absolute terms, the final consumption sectors contribute very differently to the total environmental footprint of households (Figure 3). On average, shelter and transport are the two largest sectors, accounting for nearly two thirds of both footprints. However, there are big differences between the sectors when looking at the respective contributions of each expenditure decile. For shelter there is very little difference, in both the energy and carbon footprint, between deciles. The lowest four deciles even have higher carbon footprints from shelter than most higher deciles, which can be explained by the extreme differences in intensity shown in Figure 2. Transport was the most unequal sector, with footprints in the top decile `r transport_energy_10_10` times higher than the bottom decile (corroborating findings in [@ivanova_quantifying_2020] and [@oswald_large_2020]). Manufactured goods was the second most unequal final consumption sector (10:10 ratios around `r man_goods_energy_10_10` for both footprints), followed by services (10:10 ratios of `r services_energy_10_10` for energy and `r services_co2eq_10_10` for carbon) and then food (10:10 ratios of `r food_energy_10_10` for both footprints).

```{r figure3, out.width="100%", fig.cap="Energy and carbon footprints by final consumption sector and European expenditure decile in 2015, further broken down by emission source location."}
knitr::include_graphics(here::here("analysis", "figures", "figure3.pdf"))
```

```{r values-in-text4}

co2eq_per_source = pdat %>%
  filter(indicator_type == "tCO2eq per adult eq") %>%
  group_by(five_sectors, indicator) %>%
  summarise(value = sum(value)) %>%
  mutate(share = value/sum(value))

shelter_co2eq_direct = round(((co2eq_per_source %>% filter(five_sectors == "shelter", 
                                                          indicator == "pae_co2eq_direct_t"))$share)*100, digits = 0)

energy_per_source = pdat %>%
  filter(indicator_type == "Energy GJ per adult eq") %>%
  group_by(five_sectors, indicator) %>%
  summarise(value = sum(value)) %>%
  mutate(share = value/sum(value))

shelter_energy_direct = round(((energy_per_source %>% filter(five_sectors == "shelter", 
                                                          indicator == "pae_energy_use_direct_gj"))$share)*100, digits = 0)

```

Figure 3 also shows the inequality in geographical source of the household energy and carbon footprints across final consumption sector. The shelter footprint was almost entirely domestic, with `r shelter_co2eq_direct`/`r shelter_energy_direct`% coming from direct household energy use/emissions from heating and cooling, and the rest embedded primarily along the domestic supply chain. The transport footprint, on the other hand, was around 1/4 non-European. The majority of the transport footprint, above 60%, came from vehicle fuel, either directly, or indirectly embedded along its supply chain. The manufactured goods footprint was mostly non-European, while services and food were both around 1/3 non-European. These results suggest that proposed future carbon border-adjustment mechanisms will especially impact the manufactured goods and transport footprints of the higher deciles, and to a lesser extent the food and services footprints, depending on mechanism design [@european_commission_communication_2019]. 

# Counterfactual: a 1.5°C compatible Europe

Global 1.5°C compatible decarbonisation scenarios achieve a similar climate outcome with different assumptions about the transformation of energy supply and demand, from renewable capacity, deployment of carbon-capture-and-storage (CCS), to socio-technological demand transformation. Table 1 shows some final energy use results for the year 2050 from six different decarbonisation scenarios, already adjusted from total GJ/capita to household GJ/adult equivalent. The original total GJ/capita scenario results are from different world regions (OECD, West EU, Global North, and Global), depending on the regional disaggregation of the publicly available scenario results, and so should not be interpreted as perfectly comparable with each other. For the purposes of our study, however, we are simply interested in the range of scenario results within which to situate our household footprint results, presented below in the ‘Inequality in a 1.5°C compatible Europe’ section and Figure 5.  

```{r}

df_scenario_info = read_excel(here("analysis/data/raw/scenarios.xlsx"), sheet="overview") %>%
  select(scenario, fe_gj_aeu = final_energy_gj_per_aeu_2050,
         ccs_required = primary_energy_fossil_w_ccs2050_ej,
         description) %>%
  arrange(fe_gj_aeu) %>%
  mutate(fe_gj_aeu = round(fe_gj_aeu),
         ccs_required = round(ccs_required)) %>%
  select(scenario,fe_gj_aeu)

flextable(df_scenario_info) %>%
  autofit() %>%
  set_header_labels(scenario = "scenario", 
                    fe_gj_aeu = "final energy in 2050: household GJ/adult equivalent") %>%
  set_caption("Decarbonisation scenarios.") %>%
  width(width = 3) 
```

The various global supply side scenarios (SSP1-1.9, SSP2-1.9, GEA efficiency, IEA ETP B2DS)[@riahi_shared_2017 @gea_gea_nodate @grubler_low_2018] envisage household European energy use falling from the 2015 level of 92 EJ to around 21-31 EJ by 2050, equivalent to a per household reduction from a current average of 250 GJ to 64-94 GJ per adult equivalent. The differences in energy use in 2050 in the scenarios reflect different model assumptions about the rate of expansion of renewable energy and CCS capacity. These scenarios rely on substantial amounts of CCS starting in 2020, which is still a fairly speculative technology, and we therefore interpret them as ranges for the upper limits of 1.5°C-compatible energy supply [@riahi_shared_2017 @gea_gea_nodate].

It is even more difficult to determine a lower limit for the minimum amount of energy needed for a decent life. This depends strongly on the one hand on the prevalent socio-cultural idea of what constitutes a decent life, and on the other hand, perhaps even more strongly, on the physical infrastructure available to deliver this life. The two global demand side scenarios (LED, DLE)[@grubler_low_2018 @millward-hopkins_providing_2020] that attempt to define such a limit conclude that, in principle, a very low energy footprint (between 16-53 GJ per household adult equivalent) could be sufficient. However, these scenarios rely on socio-technological transformations on a scale that, especially at the lower end, far exceeds the current political discourse on the subject. These scenarios are 1.5°C compatible without resorting to any CCS but they all implicitly (LED)[@grubler_low_2018] or explicitly (DLE)[@millward-hopkins_providing_2020] assume near complete equality of consumption across the population. To put these low energy demand numbers in perspective, the average energy footprint in our sample (250 GJ/ae) is about a factor 5 above the high estimate. Households in the first European expenditure decile had an energy footprint of 130 GJ per adult equivalent in 2015 (roughly 80 GJ/capita) even though they fell almost entirely within the Eurostat definition of severe material deprivation [@eurostat_living_nodate].

[*I struggle to separate between energy efficiency in purely technological terms, and energy efficiency of the energy service. This is relevant for the transformation we apply. Do we assume the efficiency differences are only due to inefficient energy carriers and transformation losses, or do we assume this is also due to differences in the demand/provision of energy services, e.g. more rural and car dependent. It would be easier if we could argue the former, which I will do for now.*]

Based on these two constraints, the upper limit on the supply side and the lower limit on the demand side, it is possible to make a generalized estimate of how much inequality in the distribution of energy consumption is numerically possible, if at the same time global warming is to be kept below 1.5°C above pre-industrial levels and a good life for all is to be made possible. Before we can make this evaluation, we must take into account the existing large differences in the technological efficiency of energy provision (Figure 2). Since the European expenditure deciles discussed here include large population groups (\~X persons/households) with different demand structures for energy services (urban/rural, demographic, climatic), we assume that the variation in energy intensity across deciles is largely due to technological efficiency. These differences will be adjusted in the next step.

## Current empirical best technology per sector

```{r}
pal <- wes_palette("Zissou1", 4, type = "discrete")
pal = pal[c(2,1,3,4)]

pdat_int_energy = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>% 
  mutate(intensity_energy = (total_energy_use_tj)/(total_fd_me)) %>%
  select(five_sectors, eu_q_rank, 
         intensity_energy) %>%
  filter(eu_q_rank == 10) %>%
  select(-eu_q_rank)

pdat_final_demand = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>%
  left_join(pdat_int_energy, by="five_sectors") %>%
  mutate(total_energy_use_tj_new = (total_fd_me)*intensity_energy) %>%
  mutate(total_energy_use_tj_diff = total_energy_use_tj-total_energy_use_tj_new) %>%
  select(five_sectors, eu_q_rank, 
         total_energy_use_tj_diff, total_energy_use_tj_new) %>%
  group_by(eu_q_rank) %>%
  summarise(total_energy_use_tj_new = sum(total_energy_use_tj_new)*0.000001,
            total_energy_use_tj_diff = sum(total_energy_use_tj_diff)*0.000001) %>%
  pivot_longer(-c(eu_q_rank), names_to = "indicator", values_to = "value")


p1 = ggplot(pdat_final_demand, aes(x=eu_q_rank, y=value, fill=indicator, alpha=indicator)) +
  geom_col(position = position_stack()) +
  scale_fill_manual(values=c(pal[1], pal[2]), 
                    labels=c("2015", "Best technology"), name="Energy\nfootprint") +
  scale_alpha_manual(values=c(0.3,1),labels=c("2015", "Best technology"), name="Energy\nfootprint")+
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10), 
                     labels = c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10")) +
  labs(y="Energy footprint (EJ)", x="") +
  theme_minimal() +
  coord_flip() +
  theme(legend.position="bottom")

```

```{r}

pdat_energy_country = get_sector_summary_by_country_quintile_direct() %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>%
  left_join(pdat_int_energy, by="five_sectors") %>%
  mutate(total_energy_use_tj_new = (total_fd_me)*intensity_energy) %>%
  #mutate(total_energy_use_tj_save = total_energy_use_tj_new/total_energy_use_tj*100) %>%
  select(iso2, 
         total_energy_use_tj_new, total_energy_use_tj) %>%
  group_by(iso2) %>%
  summarise(total_energy_use_tj_save = 100 - sum(total_energy_use_tj_new)/sum(total_energy_use_tj)*100)

```

```{r include=FALSE}

library(rworldmap)
library(ggthemes)



df_country_mean = pdat_energy_country %>%
  mutate(iso2 = if_else(iso2 == "EL", "GR", iso2)) %>%
  mutate(iso2 = if_else(iso2 == "UK", "GB", iso2)) %>%
  left_join(ISO_3166_1 %>% select(iso2 = Alpha_2, iso3 = Alpha_3), by="iso2")


quantile_rank_map = joinCountryData2Map(df_country_mean, 
                                        joinCode = "ISO_A3", 
                                        nameJoinColumn = "iso3")
quantile_rank_map_poly = fortify(quantile_rank_map) #extract polygons 

quantile_rank_map_poly = merge(quantile_rank_map_poly, quantile_rank_map@data, by.x="id", by.y="ADMIN", all.x=T)
quantile_rank_map_poly = quantile_rank_map_poly %>% arrange(id, order)

```

```{r dle-country, fig.width=8}
map = ggplot() + 
  geom_polygon(data = quantile_rank_map_poly, aes(long, lat, group = group), color="black") +
  geom_polygon(data = quantile_rank_map_poly, aes(long, lat, group = group, 
                                        fill=total_energy_use_tj_save)) + 
  #scale_fill_gradient(name="Mean decile \nrank", low="skyblue", high = "skyblue4", na.value = "#EEEEEE") +
  scale_fill_viridis(direction = -1, discrete = F, na.value = "white", name="Energy\nsavings (%)") +
  theme_map() +
  labs(x="",y="")+
  coord_map("bonne", lat0 = 50,xlim = c(-9, 40), ylim = c(38, 68), clip="on") +
  theme(legend.position = c(0.85, 0.6))
  
```

```{r fig.height=7, fig.width=11}

a = p1 + map + plot_annotation(tag_levels = 'a') +
  theme(plot.margin = unit(c(0.25,0.25,0.25,0.25), "cm"),
        legend.position = 'bottom',
        axis.title.y = element_text(size=13, hjust = 0.5),
        legend.text = element_text(size=12),
        legend.title = element_text(size=13))

ggsave(here("analysis", "figures", "figure4.pdf"))
```

```{r figure4, out.width="100%", fig.cap="Energy savings through sectoral best current technology by expenditure deciles a) and country b)."}
knitr::include_graphics(here::here("analysis", "figures", "figure4.pdf"))
```

Our results show that in 2015, higher-income people in higher-income countries had access to the most energy-efficient energy services across all final consumption sectors (Figure 2). Since we are interested in the numerically possible inequality in the distribution of actual consumption of goods and services in the next section, these efficiency differences must first be adjusted. In practice, this corresponds, for example, to the need for large-scale investments in the technical efficiency of heat, electricity and hot water supply, especially in Eastern Europe [@bianco_understanding_2019]. Improving technical efficiency is already a major part of the European Union (EU) platform, and new transition funds for lower-income countries, whether public or private under a Green Deal framework, need to be appropriately targeted, and at an appropriately large scale, to reduce the high intensities of consumption in the lower deciles [@european_commission_communication_2019 @european_commission_european_2020]. Figure 4 shows the energy footprint savings per decile (Fig. 4a) that would have occurred in 2015 if all deciles had the same efficiency per final consumption sector as the top decile. Around 17 EJ would have been saved in total, and the energy footprint of the bottom decile would have been nearly half its 2015 value. Fig. 4b shows saved energy per country, with Eastern European countries especially saving large proportions of their 2015 footprint, over 60% for Bulgaria and Estonia for example.

## Inequality in a 1.5°C compatible Europe

```{r}

df_energy_deciles = read_csv(here("analysis/data/raw/energy_figure_data.csv")) 

ineq_curr = df_energy_deciles$pae_energy_use_gj[10]/df_energy_deciles$pae_energy_use_gj[1]

```

```{r}

library(readxl)

df_scenario_info = read_excel(here("analysis/data/raw/scenarios.xlsx"), sheet="overview") %>%
  select(scenario, fe_gj_aeu = final_energy_gj_per_aeu_2050,
         ccs_required = primary_energy_fossil_w_ccs2050_ej,
         description) %>%
  arrange(fe_gj_aeu) %>%
  mutate(fe_gj_aeu = round(fe_gj_aeu),
         ccs_required = round(ccs_required)) 

mea = c(min(df_scenario_info$fe_gj_aeu),max(df_scenario_info$fe_gj_aeu))
mer = c(min(df_scenario_info$fe_gj_aeu),53)

c_mean_mea = round((27+mea[2])/2)
c_mean_mer = round((mer[1]+mer[2])/2)

```

```{r , fig.width=7, fig.height=5.5}

round_by = 10

df_all = readRDS(here("analysis/data/raw/scenarios_fine.rds")) %>%
  filter(eu_q_rank %in% c(1,10)) %>%
  group_by(v_mean, v_first) %>%
  summarise(ratio = last(scaled)/first(scaled)) %>%
  mutate(bin_ratio = if_else((ratio*100)%%round_by > round_by*0.5, 
                             ratio*100+(round_by-(ratio*100)%%round_by),
                             ratio*100-(ratio*100)%%round_by)) %>%
  group_by(bin_ratio, v_first) %>%
  summarise(v_mean = mean(v_mean)) %>%
  mutate(bin_ratio = bin_ratio*0.01)

df_scenario = df_all %>%
  filter(v_mean %in% df_scenario_info$fe_gj_aeu) %>%
  left_join(df_scenario_info, by=c("v_mean"="fe_gj_aeu"))

library(wesanderson)

a = df_all %>%
  ggplot(aes(x=v_first, y=bin_ratio, fill=v_mean)) +
  geom_tile() +
  geom_hline(yintercept = ineq_curr, alpha=0.8, color="grey", linetype=2) +
  geom_line(data=df_scenario, aes(color=scenario, group=scenario)) +
  annotate(geom="text", x=max(df_all$v_first)-5.7,y=ineq_curr+0.6,label = "Current (2015) 10:10 ratio") +
  #scale_fill_viridis("Mean energy\navailable") +
  scale_fill_gradient("Mean energy\navailable (GJ/ae)",
                      low=wes_palette("Chevalier1")[3], 
                      high = wes_palette("Rushmore1")[4]) +
  scale_color_manual(values=wes_palette("Darjeeling1")) +
  theme_minimal() +
  labs(x="Minimum energy requirement (GJ/ae)", y="Maximum energy inequality (10:10 ratio)", color = "Scenario")+
  theme(text=element_text(family="Liberation Sans Narrow"),
        axis.text.x = element_text(size = 13),
        axis.text.y = element_text(size = 13))# +
  #theme_ipsum()

ggsave(here("analysis", "figures", "figure5.pdf"))
```

## play around (begin)

```{r , eval = FALSE}

pdat_int_energy = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>% 
  mutate(intensity_energy = (total_energy_use_tj)/(total_fd_me)) %>%
  select(five_sectors, eu_q_rank, 
         intensity_energy) %>%
  filter(eu_q_rank == 10) %>%
  select(-eu_q_rank)

pdat_final_demand = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>%
  left_join(pdat_int_energy, by="five_sectors") %>%
  mutate(total_energy_use_tj_new = (total_fd_me)*intensity_energy) %>%
  mutate(total_energy_use_tj_diff = total_energy_use_tj-total_energy_use_tj_new) %>%
  select(eu_q_rank,total_energy_use_tj_new) %>%
  group_by(eu_q_rank) %>%
  summarise(total_energy_use_tj_new = sum(total_energy_use_tj_new)) %>%
  mutate(pae_energy_use_tj = total_energy_use_tj_new/33417583,
         pae_energy_use_gj = pae_energy_use_tj*1000)

df_energy_deciles = pdat_final_demand %>%
  select(eu_q_rank, pae_energy_use_gj)

ineq_curr = df_energy_deciles$pae_energy_use_gj[10]/df_energy_deciles$pae_energy_use_gj[1]

```

```{r , eval = FALSE}
# vectorized function that returns scaled quantiles given 
#quantile index column and column with quantile averages
#qidx: quantile index
#qavg_to_scale: column to scale
#first_target: target value of first quantile
#mean_target: target mean of scaled quantiles
scaled_quantiles <- function(.data, 
                          qidx, 
                          qavg_to_scale, 
                          first_target, 
                          mean_target) {
  
  # cumbersomely extract current quantile mean
  mean_current = .data %>%
    ungroup() %>%
    summarise(mean_cur = first(mean({{qavg_to_scale}}))) %>%
    pull(mean_cur)
    
  # cumbersomely extract current first wuantile value
  first_current = .data %>%
    ungroup() %>%
    arrange({{qidx}}) %>%
    summarise(first_cur = first({{qavg_to_scale}})) %>%
    pull(first_cur)
  
  df_tmp = .data %>%
    mutate(tmp = {{qavg_to_scale}}*mean_target/mean_current)
  
  first_tmp = df_tmp$tmp[1]
  
  df_tmp = df_tmp %>%
    mutate(scaled = mean_target-(mean_target-tmp) * (mean_target-first_target)/(mean_target-first_tmp)) %>%
    select({{qidx}}, scaled) %>%
    mutate(v_mean = mean_target, v_first = first_target)
}

```

```{r , eval = FALSE}

library(readxl)

df_scenario_info = read_excel(here("analysis/data/raw/scenarios.xlsx"), sheet="overview") %>%
  select(scenario, fe_gj_aeu = final_energy_gj_per_aeu_2050,
         ccs_required = primary_energy_fossil_w_ccs2050_ej,
         description) %>%
  arrange(fe_gj_aeu) %>%
  mutate(fe_gj_aeu = round(fe_gj_aeu),
         ccs_required = round(ccs_required)) 

mea = c(min(df_scenario_info$fe_gj_aeu),max(df_scenario_info$fe_gj_aeu))
mer = c(min(df_scenario_info$fe_gj_aeu),53)

c_mean_mea = round((27+mea[2])/2)
c_mean_mer = round((mer[1]+mer[2])/2)

```

```{r , eval = FALSE}
## run once to save file
df_all = NULL
for (min_energy in seq(from=mer[1], to=mer[2], by=0.25)) {
  for (mean_energy in seq(from=mea[1], to=mea[2], by=0.25)) {
    if (min_energy <= mean_energy) {
      df_all = df_all %>%
      bind_rows(df_energy_deciles %>%
                  scaled_quantiles(eu_q_rank, pae_energy_use_gj, min_energy, mean_energy))
    }
  }
}

saveRDS(df_all, here("analysis/data/derived/scenarios_fine_new.rds"))
```

```{r , fig.width=7, fig.height=5.5, eval = FALSE}

round_by = 10

#huh = readRDS(here("analysis/data/raw/scenarios_fine.rds"))

df_all = df_all %>% #readRDS(here("analysis/data/raw/scenarios_fine.rds"))
  filter(eu_q_rank %in% c(1,10)) %>%
  group_by(v_mean, v_first) %>%
  summarise(ratio = last(scaled)/first(scaled)) %>%
  mutate(bin_ratio = if_else((ratio*100)%%round_by > round_by*0.5, 
                             ratio*100+(round_by-(ratio*100)%%round_by),
                             ratio*100-(ratio*100)%%round_by)) %>%
  group_by(bin_ratio, v_first) %>%
  summarise(v_mean = mean(v_mean)) %>%
  mutate(bin_ratio = bin_ratio*0.01)

df_scenario = df_all %>%
  filter(v_mean %in% df_scenario_info$fe_gj_aeu) %>%
  left_join(df_scenario_info, by=c("v_mean"="fe_gj_aeu"))

library(wesanderson)

a = df_all %>%
  ggplot(aes(x=v_first, y=bin_ratio, fill=v_mean)) +
  geom_tile() +
  geom_hline(yintercept = ineq_curr, alpha=0.8, color="grey", linetype=2) +
  geom_line(data=df_scenario, aes(color=scenario, group=scenario)) +
  annotate(geom="text", x=max(df_all$v_first)-5.7,y=ineq_curr+0.6,label = "Current (2015) 10:10 ratio") +
  #scale_fill_viridis("Mean energy\navailable") +
  scale_fill_gradient("Mean energy\navailable (GJ/ae)",
                      low=wes_palette("Chevalier1")[3], 
                      high = wes_palette("Rushmore1")[4]) +
  scale_color_manual(values=wes_palette("Darjeeling1")) +
  theme_minimal() +
  labs(x="Minimum energy requirement (GJ/ae)", y="Maximum energy inequality (10:10 ratio)", color = "Scenario")+
  theme(text=element_text(family="Liberation Sans Narrow"),
        axis.text.x = element_text(size = 13),
        axis.text.y = element_text(size = 13))# +
  #theme_ipsum()
a
ggsave(here("analysis", "figures", "figure5-test.pdf"))
```

## play around (end)



Based on this counterfactual distribution of the energy footprint using homogeneous supply technologies, we can now scale down energy use across European expenditure deciles to meet supply constraints and, where necessary, "squeeze" the distribution to not undershoot minimum energy use requirements in any decile. This means that, based on the current empirical distribution, for each value combination of energy supply and minimum energy use requirement, the maximum permissible inequality can be calculated as a 10:10 ratio (Figure \@ref(fig:figure5). [*Ref to formula*]

Starting at the low end of energy supply, both the DLE and LED scenarios satisfy energy demand without resorting to CCS technologies[@millward-hopkins_providing_2020 @grubler_low_2018]. The DLE scenario explicitly envisions absolute global equality (10:10 ratio of 1) in consumption, except for small differences in required energy consumption based on climatic and demographic factors, as well as differences in population density [@millward-hopkins_providing_2020]. The LED scenario does not explicitly discuss distributional aspects beyond giving different final energy use values for the Global North (53GJ/aeu) and the Global South (27GJ/aeu) [@grubler_low_2018]. However, due to the bottom-up construction of this demand scenario, these values can be interpreted as estimates for the minimum required energy use. [*space permitting, give examples of the rather extreme nature of demand interventions here or in in scenario description/table above*]

The descriptions of the energy supply scenarios do not include specific details about how the energy footprints are distributed within the population. The energy savings here are achieved primarily through efficiency improvements, and perhaps also generally assumed demand reductions [*I actually know nothing about these scenarios, how do they achieve the reduction, and is energy demand actually resolved by country maybe?*]. However, Figure \@ref(fig:figure5) makes it clear that even with ambitious demand reductions, as in the LED scenario, a large reduction in inequality between the European expenditure deciles is required.

At current inequality levels, only the two scenarios with heavy CCS deployment and GEA efficiency are possible if we assume extremely low minimum energy use requirements (below 27 GJ/aeu). This 27 GJ/aeu is roughly the value the low-energy demand (LED) scenario gives for the Global South in 2050. If we use the value given for the Global North at 53 GJ/aeu (with strong demand side measures) then inequality would need to be drastically reduced, the 10:10 ratio more than halved, in all scenarios (including those with CCS deployment). 

```{r figure5, out.width="70%", fig.align="center", fig.cap="Mean energy available for Europe in decarbonisation scenarios, positioned in option space between a range of minimum energy requirements and range of associated maximum inequality. All expenditure deciles have 'best technology' already."}
knitr::include_graphics(here::here("analysis", "figures", "figure5.pdf"))
```

# Conclusions

Estimates of energy and carbon footprint inequality are increasingly being used to assign responsibility for climate change. At a global, regional, and within-country level, energy use and carbon emissions are often highly unequal [@piketty_carbon_2015 @kartha_carbon_2020 @gore_extreme_2015 @hubacek_global_2017 @ivanova_unequal_2020 @gore_t._confronting_2020 @wiedenhofer_unequal_2017 @golley_income_2012 @steenolsen_carbon_2016 @weber_quantifying_2008 @hardadi_implications_2020 @oswald_large_2020]. The proposed solution is often a call to reduce the carbon or energy inequality by reducing over-consumption, especially by the richest at the top of the economic distribution, which would then also reduce the energy and carbon footprints, everything else held equal. Complicating this picture, however, is the fact that energy and carbon intensities of consumption usually differ between economic groups. This is due to different consumption baskets and different access to technology. That lower-income groups tend to have higher energy and carbon intensities is an important finding from the environmental Kuznet's curve literature [@berthe_mechanisms_2015 @scruggs_political_1998]. This finding has not yet been well integrated with the current carbon and energy footprint inequality literature, that focuses more on assigning responsibility based on aggregate energy and carbon footprint inequality. 

In this study, we have found that, for Europe as a whole, lower-economic groups have higher energy and carbon intensities of consumption (although this is not necessarily true within each European country) [@sommer_carbon_2017 @kerkhof_determinants_2009]. These higher intensities come almost entirely from domestic electricity production and heating/cooling for shelter, in a handful of Central and Eastern European countries. This is already an important focus of European climate policy, but reducing these intensities should be a major priority for investment fund allocation going forward, especially within a framework such as the EU's European Green Deal [@bianco_understanding_2019]. Efforts to break consumer lock-in to these high intensities must be occurring alongside policies that seek to reduce aggregate consumption and intensities higher up in the economic distribution [@royston_invisible_2018]. Bringing intensities of consumption for all economic groups in line with those of higher-economic groups in Europe with access to the cleanest and most efficient available technologies, would substantially reduce the European household energy and carbon footprints, everything else held equal. The unequal intensity structure hinders clear conclusions on footprint inequality. We have shown that in an important sector such as shelter, lower-economic groups have almost the same level of footprint as higher-economic groups despite a fraction of the expenditure, because of their higher intensities. This can then be misleading in terms of assigning responsibility for climate change. Bringing energy and carbon intensities of all economic groups in line with the top group, and thus removing the inequality in intensity structure, would reduce the footprint, all else held equal, but *increase* energy and carbon inequality. The reduction of energy and carbon inequality is not a meaningful goal by itself. 

Current consumption inequality, however, is a barrier to achieving both scenario targets *and* providing minimum energy use (and minimum carbon in the short-term) for decent living to every European. At a global level, there is concern that achieving extreme poverty eradication may put global climate targets at risk [@hubacek_poverty_2017 @woodward_incrementum_2015 @alfredsson_why_2018]. In the European context, although less unequal than the globe as a whole, if/as lower-consumption groups increase their income and consumption, energy use and carbon emissions will increase if more efficient and cleaner technology is not adopted at a fast enough rate [@gough_recomposing_2017]. Achieving an average per capita/adult equivalent energy and carbon footprint in Europe, in scenarios that reach the Paris agreement goals, means either doing so at current consumption inequality levels and keeping lower-economic groups near or below minimum energy use levels for decent living, or reducing consumption inequality. 

<!-- The following line inserts a page break  -->

\newpage

# Associated Content

## Supplementary Information

Supplementary materials and methods, including extended discussion on limitations, and supplementary results.

# Author Information

## Corresponding Author

*email: 

## Author Contributions

I.S.J., P-P.P., and H.W. designed research; I.S.J. and P-P.P. performed research; I.S.J., P-P.P., J.T., and H.W.
interpreted results; and I.S.J., P-P.P., J.T., and H.W. wrote the paper.

## Notes

The authors declare no competing financial interest.

# Acknowledgements

\newpage

# References

<!-- The following line ensures the references appear here for the MS Word or HTML output files, rather than right at the end of the document (this will not work for PDF files):  -->

::: {#refs}
:::

\newpage

### Colophon

This report was generated on `r Sys.time()` using the following computational environment and dependencies:

```{r colophon, cache = FALSE}
# which R packages and versions?
if ("devtools" %in% installed.packages()) devtools::session_info()
```

The current Git commit details are:

```{r}
# what commit is this file at? 
if ("git2r" %in% installed.packages() & git2r::in_repository(path = ".")) git2r::repository(here::here())  
```
