User Guide

The Euromod Conector is a Python library providing tools for running simulations and interacting with the tax-benefit microsimulation model EUROMOD.

Installation

The Euromod Connector can be installed from PyPi using pip:

$ pip install euromod

Requirements

In order to run the model, we require two components: 1) the model (coded policy rules), and 2) the input microdata with the variables that respect the EUROMOD naming conventions. For more information, please, read the sections “Model” and “Input microdata” on the Download Euromod web page.

Running and navigating the model

The euromod package is object oriented and evolves around using the Model class that loads a representation of the EUROMOD model. Creating a euromod object works as follows

from euromod import Model

Create an object of the core.Model class by passing the path to the EUROMOD project:

mod=Model(r"C:\Users\serruha\Downloads\EUROMOD_RELEASES_J0.1+\EUROMOD_RELEASES_J0.1+")
mod
------------------------------
Model
------------------------------
	 countries: 28 elements
	 extensions: 12 elements
	 model_path: 'C:\\Users\\serruha\\Downloads\\EUROMOD_RELEASES_J0.1+\\EUROMOD_RELEASES_J0.1+'

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:

  • countries

  • extensions

  • model_path

The countries and extensions attributes say that they contain elements. If we take a look at countries

mod.countriesies

The Model.countries attirbute is a container storing the core.Country objects which nest the country-specific tax-benefit policies and systems.

Displays the EUROMOD default countries:

mod.countries
0: AT 
1: BE 
2: BG 
3: CY 
4: CZ 
5: DE 
6: DK 
7: EE 
8: EL 
9: ES 
10: FI
11: FR
12: HR
13: HU
14: IE
15: IT
16: LT
17: LU
18: LV
19: MT
20: NL
21: PL
22: PT
23: RO
24: SE
25: SI
26: SK
27: SL

Displaying a specific country model, e.g. Simpleland, using the two-letters country code index:

We see indeed that the euromod model contains 28 countries. In a similar fashion we could have looked what kind of extensions that are stored in the model. The countries container can be indexed by both the number of the element and the country shortcode. Let us take a look at Sweden.

mod.countries["SE"]
------------------------------
Country
------------------------------
	 ct_factors: 271 elements
	 datasets: 36 elements
	 extensions: 13 elements
	 local_extensions: COVID
	 name: 'SE'
	 policies: 28 elements
	 systems: 19 elements
	 upratefactors: 25 elements

Here we see again an informative representation of the Country object, which contains several attributes that can be accessed. In order to simulate a system we run a specific System. We can obtain the system Container of the Country Sweden

mod.countries["SE"].systems
0: SE_2006 
1: SE_2007 
2: SE_2008 
3: SE_2009 
4: SE_2010 
5: SE_2011 
6: SE_2012 
7: SE_2013 
8: SE_2014 
9: SE_2015 
10: SE_2016
11: SE_2017
12: SE_2018
13: SE_2019
14: SE_2020
15: SE_2021
16: SE_2022
17: SE_2023
18: SE_2024

Running a simulation

In order to run the tax system we need a dataset that fits the requirement to use.In case you already know which dataset you want to use one can simply load the data and run the model as follows:.

import pandas as pd
data=pd.read_csv(r"C:\Users\serruha\DATA\2022 datasets\SE_2022_b1.txt",sep="\t")
out_baseline = mod.countries["SE"].systems["SE_2021"].run(data,"SE_2022_b1")
out_baseline
Simulation for system SE_2021 with dataset SE_2022_b1 finished.
------------------------------
Simulation
------------------------------
	 constantsToOverwrite: {}
	 errors: []
	 output_filenames: ['se_2021_std.txt']
	 outputs: Pandas DataFrame of 245 variables and 20448 observations.

Note that the run function here takes the mandatory argument dataset_id, which in our case is here SE_2022_b1. This is necessary such that EUROMOD can apply the dataset specific logic with respect to setting default values and uprating. This returned us a Simulation object with multiple attributes returned. The one of interest here is outputs, which contains the outputdataset(s) returned by the microsimulation model.

out_baseline.outputs[0]
idhh idperson idmother idfather idpartner idorighh idorigperson dag dgn dec ... il_means_bhope_prel_64 il_means_bsa il_means_bhope tpr tis tad tu_bho_se_HeadID tu_bho_se_IsDependentChild tu_bho_se_IsLoneParent tu_bho_se_IsPartner
0 4416800.0 441680001.0 0.0 0.0 0.0 4416800.0 441680001.0 80.0 0.0 0.0 ... 463.630000 14776.555530 463.630000 0.0000 1267.58330 0.0 441680001.0 0.0 0.0 0.0
1 4416900.0 441690001.0 0.0 0.0 0.0 4416900.0 441690001.0 80.0 0.0 0.0 ... 10038.289690 16452.412536 10038.289690 0.0000 3647.33330 0.0 441690001.0 0.0 0.0 0.0
2 4419200.0 441920001.0 0.0 0.0 441920002.0 4419200.0 441920001.0 80.0 0.0 0.0 ... 6542.205003 12552.193817 6542.205003 0.0000 6959.58330 0.0 441920001.0 0.0 0.0 0.0
3 4419200.0 441920002.0 0.0 0.0 441920001.0 4419200.0 441920002.0 80.0 1.0 0.0 ... 11688.825003 16552.940678 11688.825003 0.0000 0.00000 0.0 441920001.0 0.0 0.0 1.0
4 4419800.0 441980001.0 0.0 0.0 0.0 4419800.0 441980001.0 80.0 1.0 0.0 ... 6022.705000 14296.703273 6022.705000 0.0000 2909.83330 0.0 441980001.0 0.0 0.0 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
20443 7172700.0 717270004.0 0.0 0.0 0.0 7172700.0 717270004.0 18.0 1.0 4.0 ... 0.000000 0.000000 0.000000 0.0000 0.00000 0.0 717270002.0 1.0 0.0 0.0
20444 7172800.0 717280001.0 0.0 0.0 0.0 7172800.0 717280001.0 19.0 0.0 3.0 ... 1454.750000 6289.899870 3988.800000 0.0000 448.16667 0.0 717280001.0 0.0 0.0 0.0
20445 7173200.0 717320001.0 0.0 0.0 0.0 7173200.0 717320001.0 19.0 0.0 0.0 ... 0.000000 0.000000 0.000000 0.0000 22617.25000 0.0 717320001.0 0.0 0.0 0.0
20446 7173200.0 717320002.0 0.0 0.0 0.0 7173200.0 717320002.0 58.0 0.0 0.0 ... 1170.856663 32469.682515 22456.858163 0.0000 0.00000 0.0 717320002.0 0.0 0.0 0.0
20447 7173200.0 717320003.0 0.0 0.0 0.0 7173200.0 717320003.0 56.0 1.0 0.0 ... 0.000000 33969.753362 24636.833500 1600.5833 0.00000 0.0 717320003.0 0.0 0.0 0.0

20448 rows × 245 columns