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
- Download the example file into your working directory by running the following function in the R terminal:
Go to your working directory and open the csv “Example_shocks_eu.csv”.
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 runcalc_di_eufor 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.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.1for a 10% increase) and less than 1 indicates a price decrease (e.g.0.9for a 10% decrease). If there is no shock in a category, keep1.Save the edited csv file.
Upload the edited file to R:
shocks <- read.csv("Example_shocks_eu.csv",
header = TRUE,
sep = ",",
dec = ".")- Run
calc_di_euwith the processed HBS data and the price shocks:
results <- calc_di_eu(data = hbs, # Output from hbs_eu()
shocks = shocks) # Edited shocks fileBy 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)
- To see the variables available for distributional impact analysis, run:
- Select a variable (e.g.
"decile") and pass it to thevarargument ofcalc_di_eu:
results <- calc_di_eu(data = hbs,
shocks = shocks,
var = "decile") # Single variable- 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)
- To see the combinations of variables available for intersectional distributional impacts, run:
- Download the intersectional variables file into your working directory:
Open “Var_Intersec_eu.csv” and delete the rows for combinations you do not want to analyse. Save the edited file.
Upload the file to R:
example_vars <- read.csv("Var_Intersec_eu.csv",
header = TRUE,
sep = ",",
dec = ".")- Pass the file to the
var_intersecargument ofcalc_di_eu:
results <- calc_di_eu(data = hbs,
shocks = shocks,
var_impact = NULL, # Skip individual variables
var_intersec = example_vars) # Intersectional combinationsExample 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)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(ifvar_intersecis 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.