Skip to contents

Step by step tutorials

Before running any of the examples below, make sure you have processed the Eurostat HBS microdata with hbs_eu(). See Preparing the data for details.

hbs <- hbs_eu(year = 2015, country = "all", path = "raw_data")

Example 1. How to enter price shocks in calc_di_eu

  1. Download the example file into your working directory by running the following function in the R terminal:
  1. Go to your working directory and open the csv “Example_shocks_eu.csv”.

  2. Define the scenarios: each column named after a country code and a scenario suffix (e.g. AT_s1, BE_s1, …, AT_s2, BE_s2, …) represents a scenario for each country. To run calc_di_eu for a single scenario, delete all columns for Scenario 2. To add another scenario, copy the Scenario 2 columns to the right and change the suffix to _s3. You can rename scenarios by changing the suffix (e.g. _shock1), but keep the country code prefix intact.

  3. Enter the price shocks: each row corresponds to a COICOP code. Enter the price change to be applied to each COICOP category for each country and each scenario. A value greater than 1 indicates a price increase (e.g. 1.1 for a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 for a 10% decrease). If there is no shock in a category, keep 1.

  4. Save the edited csv file.

  5. Upload the edited file to R:

shocks <- read.csv("Example_shocks_eu.csv",
                   header = TRUE,
                   sep = ",",
                   dec = ".")
  1. Run calc_di_eu with the processed HBS data and the price shocks:
results <- calc_di_eu(data = hbs,           # Output from hbs_eu()
                      shocks = shocks)       # Edited shocks file

By default, calc_di_eu calculates distributional impacts for all available socioeconomic variables and saves the results and figures in an outputs/ folder within your working directory.


Example 2. How to select variables for distributional impacts

Individual variables (var)

  1. To see the variables available for distributional impact analysis, run:
  1. Select a variable (e.g. "decile") and pass it to the var argument of calc_di_eu:
results <- calc_di_eu(data = hbs,
                      shocks = shocks,
                      var = "decile")     # Single variable
  1. To calculate impacts for several variables, pass a vector:
vars <- c("decile", "zone", "gender")

results <- calc_di_eu(data = hbs,
                      shocks = shocks,
                      var = vars)

For more information on available variables, see Available Variables.

Intersectional variables (var_intersec)

  1. To see the combinations of variables available for intersectional distributional impacts, run:
  1. Download the intersectional variables file into your working directory:
  1. Open “Var_Intersec_eu.csv” and delete the rows for combinations you do not want to analyse. Save the edited file.

  2. Upload the file to R:

example_vars <- read.csv("Var_Intersec_eu.csv",
                         header = TRUE,
                         sep = ",",
                         dec = ".")
  1. Pass the file to the var_intersec argument of calc_di_eu:
results <- calc_di_eu(data = hbs,
                      shocks = shocks,
                      var_impact = NULL,           # Skip individual variables
                      var_intersec = example_vars) # Intersectional combinations

Example 3. Country-level vs. EU-level results

By default, calc_di_eu calculates distributional impacts both at the EU level (across all households jointly) and at the country level (separately for each member state). To disable country-level results and obtain only EU-level results, set by_country = FALSE:

results <- calc_di_eu(data = hbs,
                      shocks = shocks,
                      by_country = FALSE)

Example 4. Update the microdata to a different year

If your price shocks come from a macroeconomic model calibrated to a year different from the HBS wave, you can update the HBS expenditure data before running the simulation using the update_hbs argument:

results <- calc_di_eu(data = hbs,           # HBS 2015 microdata
                      update_hbs = 2018,    # Update expenditure to 2018 prices
                      shocks = shocks)

Example 5. Connect with GCAM-Europe

  1. Read the GCAM-Europe prices from the database. You can indicate the database path and name, or the already created project file. Importantly, you must indicate the Baseline scenario from which the percentage prices increment will be computed. Indicate also the year of the analysis through the selected_year parameter:
# if indicating the database path and name
shocks <- get_prices_gcameurope(db_path = 'path/to/db', db_name = 'db_name', 
                                prj_name = 'new_prj_name.dat',
                                scenarios = c('scen1','scen2'), 
                                final_db_year = 2100, saveOutput = T, 
                                base_scen = 'Reference', selected_year = 2015)
                                

# if indicating the project name
shocks <- get_prices_gcameurope(prj_name = 'path/to/existing/prj.dat',
                                scenarios = c('scen1','scen2'), 
                                final_db_year = 2100, saveOutput = T, 
                                base_scen = 'Reference', selected_year = 2015)
  1. Go to your working directory and check the csv “output/GCAMEU_shocks_[prj_name].csv”. It will have each column named after a country code and a scenario suffix (e.g. AT_s1, BE_s1, …, AT_s2, BE_s2, …) representing a scenario for each country and each row a COICOP code. The values indicate the price change (e.g. 1.1 for a 10% increase and 0.9 for a 10% decrease). If there is no shock in a category, keep 1.

  2. Run calc_di_eu with the processed HBS data and the price shocks:

results <- calc_di_eu(data = hbs,            # Output from hbs_eu()
                    shocks = shocks)       # GCAM-Europe shocks file

By default, calc_di_eu calculates distributional impacts for all available socioeconomic variables and saves the results and figures in an outputs/ folder within your working directory.


Outputs

calc_di_eu returns a list with two elements:

  • di: a data frame with the basic distributional impacts per selected variable and scenario.
  • dii (if var_intersec is specified): a data frame with the intersectional distributional impacts.

By default, results are saved to the outputs/ folder and figures are generated automatically. To suppress saving, set save = FALSE and fig = FALSE.