Step by step tutorials

Example 1. How to enter price shocks in calc_di

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

  2. Define the scenarios: Each column Scenario__ is a scenario. To run calc_di for 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.

  3. 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.

  4. Save the edited csv file.

  5. 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
  1. Indicate to calc_di that 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)

  1. To know the variables for which the calculation of basic distributional impacts is available run the following function.
  1. Select one of the variables that the function returns in the console. For example, “ZONA”.

  2. Enter that variable in the var_impact argument of calc_di. By default, var_impact = "all" , i.e. it calculates the distributional impacts for all variables returned by available_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
  1. In case you want to calculate distributional impacts for several variables, e.g. for “ZONE” and “TAMAMU”, create a vector with these variables and enter it in the var_impact argument of calc_di.
#Create a vector
vars <- c("ZONA", "TAMAMU")

#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 passed

Introduce a set of variables (var_intersec)

  1. 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.
  1. 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.
  1. 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
  1. Enter the file in the var_intersec argument in calc_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