We start with loading the euromod toolbox and creating a Model object from a EUROMOD model. See the installation guide on how to download and install the toolbox and its dependencies.
mod = euromod("C:\EUROMOD_RELEASES_I6.0+");
mod
1×1 Modelwith properties: extensions: [11×1 Extension] countries: [28×1 Country] modelpath: "C:\EUROMOD_RELEASES_I6.0+"
Note that every object that is related to the EUROMOD project comes with an informative description. Here we can see that the model has 3 relevant attributes to the user:
The countries and extensions attributes contain elements of the respective objects. If we take a look at countries:
mod.countries
28×1 Countryarray: 1: AT 2: BE 3: BG 4: CY 5: CZ 6: DE 7: DK 8: EE 9: EL 10: ES 11: FI 12: FR 13: HR 14: HU 15: IE 16: IT 17: LT 18: LU 19: LV 20: MT 21: NL 22: PL 23: PT 24: RO 25: se 26: SI 27: SK 28: SL
We see indeed that the euromod model contains 28 countries. In a similar fashion we can look what kind of extensions are stored in the model. The countries class array can be indexed by both the number of the element and the country shortcode. Let us take a look at Sweden:
mod.countries("SE") 1×1 Countrywith properties: datasets: [27×1 Dataset] extensions: [12×1 Extension] local_extensions: COVID name: "SE" parent: [1×1 Model] policies: [26×1 Policy] systems: [18×1 System]
Here we see again an informative representation of the Country class, which contains several properties that can be accessed. We can for example take a look at the first 10 policies that are stored in the country:
mod.countries("SE").policies(1:10) 10×1 Policyarray: 1: setdefault_se | | DEF: SET DEFAULT 2: uprate_se | | DEF: UPRATING FACTORS 3: ConstDef_se | | DEF: CONSTANTS 4: IlsDef_se | | DEF: INCOME CONCEPTS (standardized) 5: IlsUDBdef_se | | DEF: INCOME CONCEPTS (UDB) 6: ildef_se | | DEF: INCOME CONCEPTS (non-standardized) 7: random_se | | DEF: Random assignment 8: TransLMA_se | | DEF: Modelling labour market transitions (DO NOT SWITCH ON; ONLY WORKS WITH THE LMA ADD-ON) 9: tudef_se | | DEF: ASSESSMENT UNITS 10: yem_se | (with switch set for MWA) | DEF: minimum wage
Say that we are interested in running the tax system for the year 2021 of Sweden. Building further on the previous example we can look at the tax-systems contained in the model for Sweden:
mod.SE.systems
18×1 Systemarray: 1: SE_2006 2: SE_2007 3: SE_2008 4: SE_2009 5: SE_2010 6: SE_2011 7: SE_2012 8: SE_2013 9: SE_2014 10: SE_2015 11: SE_2016 12: SE_2017 13: SE_2018 14: SE_2019 15: SE_2020 16: SE_2021 17: SE_2022 18: SE_2023
In order to run the tax system we need a dataset that fits the requirement to use. The model however provides us with a list of datasets that are configured already:
mod.SE.SE_2021.datasets
5×1 DatasetInSystemarray: 1: training_data | 2: SE_2019_a1 | 3: SE_2020_b1 | 4: SE_2021_hhot | 5: SE_2021_b1 | best match
Here we see that there are multiple datasets configured, but that PL_2021_b1 is set as the best match dataset for this taxsystem. Provided that you have the microdata stored somewhere, you can then load it as a table and run the model in the following way:
data = readtable("SE_2021_b1.txt"); S=mod.("SE").("SE_2021").run(data,"SE_2021_b1"); S
1×1 Simulationwith properties: outputs: {[21671×240 table]} settings: [1×1 struct] output_filenames: "se_2021_std" errors: [0×1 string] output 1 : [21671x240 table] idhh idperson idmother idfather idpartner idorighh idorigperson dag dgn dec 200 20001 0 0 0 200 20001 45 1 0 300 30001 0 0 30002 300 30001 26 1 0 300 30002 0 0 30001 300 30002 26 0 0 500 50001 0 0 50002 500 50001 37 1 0 500 50002 0 0 50001 500 50002 33 0 0 500 50003 50002 50001 0 500 50003 4 1 1 ...
This returns a Simulation object with multiple properties. The one of interest here is outputs, which contains the output dataset(s) of type table returned by the microsimulation model.
outputdata_baseline = S.outputs{1};
outputdata_baseline(1:10,1:10) 10×10 tablearray: idhh idperson idmother idfather idpartner idorighh idorigperson dag dgn dec ____ ________ ________ ________ _________ ________ ____________ ___ ___ ___ 200 20001 0 0 0 200 20001 45 1 0 300 30001 0 0 30002 300 30001 26 1 0 300 30002 0 0 30001 300 30002 26 0 0 500 50001 0 0 50002 500 50001 37 1 0 500 50002 0 0 50001 500 50002 33 0 0 500 50003 50002 50001 0 500 50003 4 1 1 600 60001 0 0 0 600 60001 44 1 0 700 70001 0 0 0 700 70001 28 0 6 900 90001 0 0 0 900 90001 77 1 0 1300 1.3e+05 0 0 1.3e+05 1300 1.3e+05 54 0 0
One of the advantages of using the Matlab Connectors is the ability to run many counterfactual scenario’s for the EUROMOD model. One can for example change the Tax Free income limit in Poland. There are multiple ways to do this via the euromod toolbox in Matlab, but one very straightforward way is to use the constantsToOverwrite Name-Value input argument:
S=mod.('SE').('SE_2021').run(data,"SE_2021_b1",constantsToOverwrite={["$tinna_rate2",""],'0.4'});
outputdata_changed= S.outputs{1};
sum(outputdata_changed.ils_dispy - outputdata_baseline.ils_dispy) The Name-Value input argument constantsToOverwrite specifies which constants to overwrite in the policy spline. It is a N×1 cell array of strings. The first element is itself a 1×2 string indicating the targetted constant and the order (leave an empty string if it is NaN), and the second element is the value of type string to overwrite with. The default is [].
Run the simulation for the Swedish system SE_2021 including the Marginal Tax-Rate add-on, using optional Name-Value input argument addons:
S=mod.('SE').('SE_2021').run(data,"SE_2021_b1",addons=["MTR","MTR"]);
S
1×1 Simulationwith properties: outputs: {[21671×246 table] [21671×39 table]} settings: [1×1 struct] output_filenames: ["se_2021_base_mtr" "se_2021_mtr"] errors: [0×1 string] output 1 : [21671x246 table] idhh idperson idmother idfather idpartner idorighh idorigperson dag dgn dec 200 20001 0 0 0 200 20001 45 1 0 300 30001 0 0 30002 300 30001 26 1 0 300 30002 0 0 30001 300 30002 26 0 0 500 50001 0 0 50002 500 50001 37 1 0 500 50002 0 0 50001 500 50002 33 0 0 500 50003 50002 50001 0 500 50003 4 1 1 ... output 2 : [21671x39 table] idhh idperson dwt yem_backup ils_earns_backup ils_earns_mtr_base1 ils_dispy_mtr_base1 ils_pen_mtr_base1 ils_benmt_mtr_base1 ils_bennt_mtr_base1 200 20001 9.200411e+02 5.634323e+04 5.634323e+04 5.634323e+04 6.499764e+04 0 0 7.019343e+03 300 30001 8.892741e+02 4.004048e+04 4.089143e+04 4.089143e+04 3.055700e+04 0 0 0 300 30002 8.892741e+02 2.400465e+04 2.448169e+04 2.448169e+04 1.974766e+04 0 0 0 500 50001 9.082533e+02 4.805374e+04 4.805374e+04 4.805374e+04 3.600150e+04 0 0 1.675232e+03 500 50002 9.082533e+02 0 0 0 2.794360e+03 0 0 2.794360e+03 500 50003 9.082533e+02 0 0 0 0 0 0 0 ...
As one can see there are two datasets returned by the model. Both of them can be accessed. The average marginal tax rate for example can be straightforwardly computed as:
mean(S.outputs{2}{:,'mtrpc'});The optional parameter addons that we passed to the run command is a string array of Name-Value arguments, with EUROMOD Addons to be integrated in the spine. For each Addon, specify the name of the Addon and the name of the system in the Addon to be integrated (typically, it is the name of Addon_two-letter country code e.g. LMA_AT). Default is [].
Run the simulation for the Swedish system SE_2021 switching on the Benefit Take-up Adjustment extension ‘BTA’ using the optional Name-Value input argument switches:
S_BTA=mod.('SE').('SE_2021').run(data,"SE_2021_b1",switches=["BTA",true]);
S
1×1 Simulationwith properties: outputs: {[21671×246 table] [21671×39 table]} settings: [1×1 struct] output_filenames: ["se_2021_base_mtr" "se_2021_mtr"] errors: [0×1 string] output 1 : [21671x246 table] idhh idperson idmother idfather idpartner idorighh idorigperson dag dgn dec 200 20001 0 0 0 200 20001 45 1 0 300 30001 0 0 30002 300 30001 26 1 0 300 30002 0 0 30001 300 30002 26 0 0 500 50001 0 0 50002 500 50001 37 1 0 500 50002 0 0 50001 500 50002 33 0 0 500 50003 50002 50001 0 500 50003 4 1 1 ... output 2 : [21671x39 table] idhh idperson dwt yem_backup ils_earns_backup ils_earns_mtr_base1 ils_dispy_mtr_base1 ils_pen_mtr_base1 ils_benmt_mtr_base1 ils_bennt_mtr_base1 200 20001 9.200411e+02 5.634323e+04 5.634323e+04 5.634323e+04 6.499764e+04 0 0 7.019343e+03 300 30001 8.892741e+02 4.004048e+04 4.089143e+04 4.089143e+04 3.055700e+04 0 0 0 300 30002 8.892741e+02 2.400465e+04 2.448169e+04 2.448169e+04 1.974766e+04 0 0 0 500 50001 9.082533e+02 4.805374e+04 4.805374e+04 4.805374e+04 3.600150e+04 0 0 1.675232e+03 500 50002 9.082533e+02 0 0 0 2.794360e+03 0 0 2.794360e+03 500 50003 9.082533e+02 0 0 0 0 0 0 0 ...
The optional parameter switches is a string array of Name-Value arguments, which define the EUROMOD extensions to be switched on or off in the simulation. For each extension specify the short name of the Extension and a logical value. Default is [].
[1] Documentation EUROMOD - Tax-benefit microsimulation model for the European Union.
You have a modified version of this example. Do you want to open this example with your edits?