{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# User Guide\n", "\n", "The Euromod Conector is a Python library providing tools for running simulations and interacting with the tax-benefit microsimulation model [EUROMOD](https://euromod-web.jrc.ec.europa.eu \"https://euromod-web.jrc.ec.europa.eu\"). \n", "\n", "## Installation\n", "The Euromod Connector can be installed from [PyPi](https://test.pypi.org/project/euromod/) using _pip_:\n", "```bash\n", "$ pip install euromod\n", "```\n", "\n", "### Requirements\n", "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.\n", "For more information, please, read the sections \"Model\" and \"Input microdata\" on the [Download Euromod](https://euromod-web.jrc.ec.europa.eu/download-euromod \"https://euromod-web.jrc.ec.europa.eu/download-euromod\") web page.\n", "\n", "## Running and navigating the model\n", "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" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from euromod import Model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create an object of the `core.Model` class by passing the path to the EUROMOD project: " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "Model\n", "------------------------------\n", "\t countries: 28 elements\n", "\t extensions: 12 elements\n", "\t model_path: 'C:\\\\Users\\\\serruha\\\\Downloads\\\\EUROMOD_RELEASES_J0.1+\\\\EUROMOD_RELEASES_J0.1+'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod=Model(r\"C:\\Users\\serruha\\Downloads\\EUROMOD_RELEASES_J0.1+\\EUROMOD_RELEASES_J0.1+\")\n", "mod" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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:\n", "- countries\n", "- extensions\n", "- model_path\n", " \n", "The countries and extensions attributes say that they contain elements. If we take a look at countries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "mod.countriesies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `Model.countries` attirbute is a container storing the `core.Country` objects which nest the country-specific tax-benefit policies and systems.\n", "\n", "Displays the EUROMOD default countries:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0: AT \n", "1: BE \n", "2: BG \n", "3: CY \n", "4: CZ \n", "5: DE \n", "6: DK \n", "7: EE \n", "8: EL \n", "9: ES \n", "10: FI\n", "11: FR\n", "12: HR\n", "13: HU\n", "14: IE\n", "15: IT\n", "16: LT\n", "17: LU\n", "18: LV\n", "19: MT\n", "20: NL\n", "21: PL\n", "22: PT\n", "23: RO\n", "24: SE\n", "25: SI\n", "26: SK\n", "27: SL" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Displaying a specific country model, e.g. Simpleland, using the two-letters country code index:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "Country\n", "------------------------------\n", "\t ct_factors: 271 elements\n", "\t datasets: 36 elements\n", "\t extensions: 13 elements\n", "\t local_extensions: COVID\n", "\t name: 'SE'\n", "\t policies: 28 elements\n", "\t systems: 19 elements\n", "\t upratefactors: 25 elements" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0: SE_2006 \n", "1: SE_2007 \n", "2: SE_2008 \n", "3: SE_2009 \n", "4: SE_2010 \n", "5: SE_2011 \n", "6: SE_2012 \n", "7: SE_2013 \n", "8: SE_2014 \n", "9: SE_2015 \n", "10: SE_2016\n", "11: SE_2017\n", "12: SE_2018\n", "13: SE_2019\n", "14: SE_2020\n", "15: SE_2021\n", "16: SE_2022\n", "17: SE_2023\n", "18: SE_2024" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].systems" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Running a simulation\n", "\n", "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:." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Simulation for system SE_2021 with dataset SE_2022_b1 finished.\n" ] }, { "data": { "text/plain": [ "------------------------------\n", "Simulation\n", "------------------------------\n", "\t constantsToOverwrite: {}\n", "\t errors: []\n", "\t output_filenames: ['se_2021_std.txt']\n", "\t outputs: Pandas DataFrame of 245 variables and 20448 observations." ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "data=pd.read_csv(r\"C:\\Users\\serruha\\DATA\\2022 datasets\\SE_2022_b1.txt\",sep=\"\\t\")\n", "out_baseline = mod.countries[\"SE\"].systems[\"SE_2021\"].run(data,\"SE_2022_b1\")\n", "out_baseline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | idhh | \n", "idperson | \n", "idmother | \n", "idfather | \n", "idpartner | \n", "idorighh | \n", "idorigperson | \n", "dag | \n", "dgn | \n", "dec | \n", "... | \n", "il_means_bhope_prel_64 | \n", "il_means_bsa | \n", "il_means_bhope | \n", "tpr | \n", "tis | \n", "tad | \n", "tu_bho_se_HeadID | \n", "tu_bho_se_IsDependentChild | \n", "tu_bho_se_IsLoneParent | \n", "tu_bho_se_IsPartner | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "4416800.0 | \n", "441680001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "4416800.0 | \n", "441680001.0 | \n", "80.0 | \n", "0.0 | \n", "0.0 | \n", "... | \n", "463.630000 | \n", "14776.555530 | \n", "463.630000 | \n", "0.0000 | \n", "1267.58330 | \n", "0.0 | \n", "441680001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 1 | \n", "4416900.0 | \n", "441690001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "4416900.0 | \n", "441690001.0 | \n", "80.0 | \n", "0.0 | \n", "0.0 | \n", "... | \n", "10038.289690 | \n", "16452.412536 | \n", "10038.289690 | \n", "0.0000 | \n", "3647.33330 | \n", "0.0 | \n", "441690001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2 | \n", "4419200.0 | \n", "441920001.0 | \n", "0.0 | \n", "0.0 | \n", "441920002.0 | \n", "4419200.0 | \n", "441920001.0 | \n", "80.0 | \n", "0.0 | \n", "0.0 | \n", "... | \n", "6542.205003 | \n", "12552.193817 | \n", "6542.205003 | \n", "0.0000 | \n", "6959.58330 | \n", "0.0 | \n", "441920001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 3 | \n", "4419200.0 | \n", "441920002.0 | \n", "0.0 | \n", "0.0 | \n", "441920001.0 | \n", "4419200.0 | \n", "441920002.0 | \n", "80.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "11688.825003 | \n", "16552.940678 | \n", "11688.825003 | \n", "0.0000 | \n", "0.00000 | \n", "0.0 | \n", "441920001.0 | \n", "0.0 | \n", "0.0 | \n", "1.0 | \n", "
| 4 | \n", "4419800.0 | \n", "441980001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "4419800.0 | \n", "441980001.0 | \n", "80.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "6022.705000 | \n", "14296.703273 | \n", "6022.705000 | \n", "0.0000 | \n", "2909.83330 | \n", "0.0 | \n", "441980001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 20443 | \n", "7172700.0 | \n", "717270004.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "7172700.0 | \n", "717270004.0 | \n", "18.0 | \n", "1.0 | \n", "4.0 | \n", "... | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.0000 | \n", "0.00000 | \n", "0.0 | \n", "717270002.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "
| 20444 | \n", "7172800.0 | \n", "717280001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "7172800.0 | \n", "717280001.0 | \n", "19.0 | \n", "0.0 | \n", "3.0 | \n", "... | \n", "1454.750000 | \n", "6289.899870 | \n", "3988.800000 | \n", "0.0000 | \n", "448.16667 | \n", "0.0 | \n", "717280001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 20445 | \n", "7173200.0 | \n", "717320001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "7173200.0 | \n", "717320001.0 | \n", "19.0 | \n", "0.0 | \n", "0.0 | \n", "... | \n", "0.000000 | \n", "0.000000 | \n", "0.000000 | \n", "0.0000 | \n", "22617.25000 | \n", "0.0 | \n", "717320001.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 20446 | \n", "7173200.0 | \n", "717320002.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "7173200.0 | \n", "717320002.0 | \n", "58.0 | \n", "0.0 | \n", "0.0 | \n", "... | \n", "1170.856663 | \n", "32469.682515 | \n", "22456.858163 | \n", "0.0000 | \n", "0.00000 | \n", "0.0 | \n", "717320002.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 20447 | \n", "7173200.0 | \n", "717320003.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "7173200.0 | \n", "717320003.0 | \n", "56.0 | \n", "1.0 | \n", "0.0 | \n", "... | \n", "0.000000 | \n", "33969.753362 | \n", "24636.833500 | \n", "1600.5833 | \n", "0.00000 | \n", "0.0 | \n", "717320003.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
20448 rows × 245 columns
\n", "