Step by step tutorials
Example 1. How to enter price shocks in calc_di
- Download the example file into your directory by running the following function in the R terminal:
Go to your working directory and open the csv “Example_shocks”.
Define the scenarios: Each column Scenario__ is a scenario. To run
calc_difor a single scenario delete column Scenario2. To add another scenario, copy column Scenario2 to the right and change the heading to Scenario3. You can also rename the scenarios by changing the heading of each column (e.g. renaming “Scenario1” to “Shock1”). It is recommended to keep the names short, as additional variables with this name will be created later and inserted into the graphs.Enter the price shocks: Each row corresponds to a COICOP code [1] . Enter in each row the price change to be applied to each coicop in each scenario (column). A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a 10% decrease). If there is no shock in that category, keep 1.
Save the edited csv file.
Upload the edited file to R by running the following function in the terminal:
exampledf <- read.csv(file_name, # File name or full file path
header = TRUE, # Header indicator (set to TRUE)
sep = ",", # Value separator used in the file
dec = ".", # Decimal point format used
...) # Additional arguments to be passed- Indicate to
calc_dithat this is the file from which to take the price shocks to be applied.
calc_di( year, # Base year for the simulation (available 2006-2021)
elevate = F, # Elevation of raw data (set to FALSE)
shocks = exampledf, # Indicate here the name of the uploaded file with shocks
...) # Additional arguments to be passed[1] The COICOP variables of the file correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset.
Example 2. How to enter the variables for which we want
calc_di to calculate distributional impacts
Introduce individual variables (var_impact)
- To know the variables for which the calculation of basic
distributional impacts is available run the following function.
Select one of the variables that the function returns in the console. For example, “DECILE”.
Enter that variable in the
var_impactargument ofcalc_di. By default,var_impact = "all", i.e. it calculates the distributional impacts for all variables returned byavailable_var_impact(). For more information on variables click here.
calc_di(year, # Base year for the simulation
elevate = F, # Elevation of raw data (set to FALSE)
shocks = exampledf, # Name of the uploaded file with shocks
var_impact = "DECILE", # Indicate here the socioeconomic variable to be used
...) # Additional arguments to be passed- In case you want to calculate distributional impacts for several
variables, e.g. for “ZONE” and “QUINTILE”, create a vector with these
variables and enter it in the
var_impactargument ofcalc_di.
#Create a vector
vars <- c("ZONE", "QUINTILE")
#Introduce the vector in var_impact argument
calc_di(year, # Base year for the simulation
elevate = F, # Elevation of raw data (set to FALSE)
shocks = exampledf, # Name of the uploaded file with shocks
var_impact = vars, # Indicate here the name of the vector with the selected variables
...) # Additional arguments to be passedIntroduce a set of variables (var_intersec)
- To know the set of variables for which the calculation of intersectional distributional impacts is available run the following function. The function returns a table with the set of variables (category_a and category_b) for which the calculation of intersectional distributional impacts is available.
- Create a table with the set of variables for which you want to calculate distributional impacts in the format predefined in the package. To do this, run the following function that saves a csv file in your directory, open it and delete the rows with the combinations you are not interested in. Once you have a table with only the set of variables you are interested in, save it.
- Upload the edited file to R by running the following function in the terminal:
example_vars <- read.csv(file_name, # File name or full file path
header = TRUE, # Header indicator (set to TRUE)
sep = ",", # Value separator used in the file
dec = ".", # Decimal point format used
...) # Additional arguments to be passed- Enter the file in the
var_intersecargument incalc_di. By default,var_intersec = NULL, i.e. iif no data is entered in this argument it will not calculate any intersectional impacts, it will only calculate distributional impacts for individual variables. For more information on variables click here.
calc_di(year, # Base year for the simulation
elevate = F, # Elevation of raw data (set to FALSE)
shocks = exampledf, # Name of the uploaded file with shocks
var_intersec = example_vars, # Indicate here the file name of the selected set of variables
...) # Additional arguments