{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idhhidpersonidmotheridfatheridpartneridorighhidorigpersondagdgndec...il_means_bhope_prel_64il_means_bsail_means_bhopetprtistadtu_bho_se_HeadIDtu_bho_se_IsDependentChildtu_bho_se_IsLoneParenttu_bho_se_IsPartner
04416800.0441680001.00.00.00.04416800.0441680001.080.00.00.0...463.63000014776.555530463.6300000.00001267.583300.0441680001.00.00.00.0
14416900.0441690001.00.00.00.04416900.0441690001.080.00.00.0...10038.28969016452.41253610038.2896900.00003647.333300.0441690001.00.00.00.0
24419200.0441920001.00.00.0441920002.04419200.0441920001.080.00.00.0...6542.20500312552.1938176542.2050030.00006959.583300.0441920001.00.00.00.0
34419200.0441920002.00.00.0441920001.04419200.0441920002.080.01.00.0...11688.82500316552.94067811688.8250030.00000.000000.0441920001.00.00.01.0
44419800.0441980001.00.00.00.04419800.0441980001.080.01.00.0...6022.70500014296.7032736022.7050000.00002909.833300.0441980001.00.00.00.0
..................................................................
204437172700.0717270004.00.00.00.07172700.0717270004.018.01.04.0...0.0000000.0000000.0000000.00000.000000.0717270002.01.00.00.0
204447172800.0717280001.00.00.00.07172800.0717280001.019.00.03.0...1454.7500006289.8998703988.8000000.0000448.166670.0717280001.00.00.00.0
204457173200.0717320001.00.00.00.07173200.0717320001.019.00.00.0...0.0000000.0000000.0000000.000022617.250000.0717320001.00.00.00.0
204467173200.0717320002.00.00.00.07173200.0717320002.058.00.00.0...1170.85666332469.68251522456.8581630.00000.000000.0717320002.00.00.00.0
204477173200.0717320003.00.00.00.07173200.0717320003.056.01.00.0...0.00000033969.75336224636.8335001600.58330.000000.0717320003.00.00.00.0
\n", "

20448 rows × 245 columns

\n", "
" ], "text/plain": [ " idhh idperson idmother idfather idpartner idorighh \\\n", "0 4416800.0 441680001.0 0.0 0.0 0.0 4416800.0 \n", "1 4416900.0 441690001.0 0.0 0.0 0.0 4416900.0 \n", "2 4419200.0 441920001.0 0.0 0.0 441920002.0 4419200.0 \n", "3 4419200.0 441920002.0 0.0 0.0 441920001.0 4419200.0 \n", "4 4419800.0 441980001.0 0.0 0.0 0.0 4419800.0 \n", "... ... ... ... ... ... ... \n", "20443 7172700.0 717270004.0 0.0 0.0 0.0 7172700.0 \n", "20444 7172800.0 717280001.0 0.0 0.0 0.0 7172800.0 \n", "20445 7173200.0 717320001.0 0.0 0.0 0.0 7173200.0 \n", "20446 7173200.0 717320002.0 0.0 0.0 0.0 7173200.0 \n", "20447 7173200.0 717320003.0 0.0 0.0 0.0 7173200.0 \n", "\n", " idorigperson dag dgn dec ... il_means_bhope_prel_64 \\\n", "0 441680001.0 80.0 0.0 0.0 ... 463.630000 \n", "1 441690001.0 80.0 0.0 0.0 ... 10038.289690 \n", "2 441920001.0 80.0 0.0 0.0 ... 6542.205003 \n", "3 441920002.0 80.0 1.0 0.0 ... 11688.825003 \n", "4 441980001.0 80.0 1.0 0.0 ... 6022.705000 \n", "... ... ... ... ... ... ... \n", "20443 717270004.0 18.0 1.0 4.0 ... 0.000000 \n", "20444 717280001.0 19.0 0.0 3.0 ... 1454.750000 \n", "20445 717320001.0 19.0 0.0 0.0 ... 0.000000 \n", "20446 717320002.0 58.0 0.0 0.0 ... 1170.856663 \n", "20447 717320003.0 56.0 1.0 0.0 ... 0.000000 \n", "\n", " il_means_bsa il_means_bhope tpr tis tad \\\n", "0 14776.555530 463.630000 0.0000 1267.58330 0.0 \n", "1 16452.412536 10038.289690 0.0000 3647.33330 0.0 \n", "2 12552.193817 6542.205003 0.0000 6959.58330 0.0 \n", "3 16552.940678 11688.825003 0.0000 0.00000 0.0 \n", "4 14296.703273 6022.705000 0.0000 2909.83330 0.0 \n", "... ... ... ... ... ... \n", "20443 0.000000 0.000000 0.0000 0.00000 0.0 \n", "20444 6289.899870 3988.800000 0.0000 448.16667 0.0 \n", "20445 0.000000 0.000000 0.0000 22617.25000 0.0 \n", "20446 32469.682515 22456.858163 0.0000 0.00000 0.0 \n", "20447 33969.753362 24636.833500 1600.5833 0.00000 0.0 \n", "\n", " tu_bho_se_HeadID tu_bho_se_IsDependentChild tu_bho_se_IsLoneParent \\\n", "0 441680001.0 0.0 0.0 \n", "1 441690001.0 0.0 0.0 \n", "2 441920001.0 0.0 0.0 \n", "3 441920001.0 0.0 0.0 \n", "4 441980001.0 0.0 0.0 \n", "... ... ... ... \n", "20443 717270002.0 1.0 0.0 \n", "20444 717280001.0 0.0 0.0 \n", "20445 717320001.0 0.0 0.0 \n", "20446 717320002.0 0.0 0.0 \n", "20447 717320003.0 0.0 0.0 \n", "\n", " tu_bho_se_IsPartner \n", "0 0.0 \n", "1 0.0 \n", "2 0.0 \n", "3 1.0 \n", "4 0.0 \n", "... ... \n", "20443 0.0 \n", "20444 0.0 \n", "20445 0.0 \n", "20446 0.0 \n", "20447 0.0 \n", "\n", "[20448 rows x 245 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "out_baseline.outputs[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Navigating the model\n", "The `Model` object actually contains a full representation of the model that can be accessed using it's attributes. The implementation in Python mimicks the hierarchical structure of the EUROMOD User Interface. A full description of the available types can be found in the API reference.\n", "#### The spine\n", "The spine of EUROMOD is what represents the series of calculations with respect taxes and benefits.\n", "The spine consists out of three hierarchically ordered elements:\n", "- Policy\n", " - Function\n", " - Parameter\n", " \n", "The connector mimmicks this hierarchical implementation through an object-oriented representation. The three hierarchical elements are defined on the `Country` level and implemented on the `System` level.\n", "\n", "Let us take a look at the policies, which are an attribute of the `Country` object." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0: setdefault_se | | DEF: SET DEFAULT \n", "1: uprate_se | | DEF: UPRATING FACTORS \n", "2: ConstDef_se | | DEF: CONSTANTS \n", "3: IlsDef_se | | DEF: INCOME CONCEPTS (standardized) \n", "4: IlsUDBdef_se | | DEF: INCOME CONCEPTS (UDB) \n", "5: ildef_se | | DEF: INCOME CONCEPTS (non-standardized) \n", "6: random_se | | DEF: Random assignment \n", "7: TransLMA_se | | DEF: Modelling labour market transitions (DO NOT S ... \n", "8: tudef_se | | DEF: ASSESSMENT UNITS \n", "9: yem_se | (with switch set for MWA) | DEF: minimum wage \n", "10: neg_se | | DEF: recode negative self-employment income to zer ... \n", "11: yemcomp_se | | BEN: wage compensation scheme COVID-19 (ONLY WORK ... \n", "12: hhot_switch_se | (with switch set for HHoT_un, WEB) | DEF: switch on bunct for HHoT extension \n", "13: bunct_se | | BEN: unemployment benefit (contributory) \n", "14: bfapl_se | (with switch set for PBE) | BEN: Parental leave benefit \n", "15: bpa_se | (with switch set for PBE) | BEN: Special leave days other parent (10 days) \n", "16: tscee_se | | SIC: Employee Social Insurance contribution \n", "17: tscer_se | | SIC: Employer Social Insurance contribution \n", "18: tscse_se | | SIC: Self-employed Social Insurance contribution \n", "19: tin_se | | TAX: Personal Income tax \n", "20: tinkt_se | | TAX: Tax on Capital Income \n", "21: bch_se | | BEN: Child benefit \n", "22: bho_se | | BEN: Housing allowance \n", "23: bhope_se | | BEN: Housing allowance for pensioners \n", "24: bsamt_se | | BEN: Social Assistance (means-tested) \n", "25: tco_se | | TAX: Commodities \n", "26: output_std_se | | DEF: STANDARD OUTPUT INDIVIDUAL LEVEL \n", "27: output_std_hh_se | | DEF: STANDARD OUTPUT HOUSEHOLD LEVEL " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].policies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As one can see the `policies` attribute is a Container object here, and it's elements which are of the type `Policy` here are accessible." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "Policy\n", "------------------------------\n", "\t ID: '6B7D3970-7A4E-4BAC-BBB1-43ABBD3C989A'\n", "\t comment: 'BEN: Housing allowance'\n", "\t extensions: 0 elements\n", "\t functions: 18 elements\n", "\t name: 'bho_se'\n", "\t order: '23'\n", "\t private: 'no'\n", "\t spineOrder: '23'\n", "\t system_elements: 0 elements" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].policies[22]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The implementation of a policy is accessible through the `System` object." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0: setdefault_se | on | DEF: SET DEFAULT \n", "1: uprate_se | on | DEF: UPRATING FACTORS \n", "2: ConstDef_se | on | DEF: CONSTANTS \n", "3: IlsDef_se | on | DEF: INCOME CONCEPTS (standardized) \n", "4: IlsUDBdef_se | on | DEF: INCOME CONCEPTS (UDB) \n", "5: ildef_se | on | DEF: INCOME CONCEPTS (non-standardized) \n", "6: random_se | on | DEF: Random assignment \n", "7: TransLMA_se | off | DEF: Modelling labour market transitions (DO NOT S ... \n", "8: tudef_se | on | DEF: ASSESSMENT UNITS \n", "9: yem_se | off (with switch set for MWA) | DEF: minimum wage \n", "10: neg_se | on | DEF: recode negative self-employment income to zer ... \n", "11: yemcomp_se | on | BEN: wage compensation scheme COVID-19 (ONLY WORK ... \n", "12: hhot_switch_se | on (with switch set for HHoT_un, WEB) | DEF: switch on bunct for HHoT extension \n", "13: bunct_se | off | BEN: unemployment benefit (contributory) \n", "14: bfapl_se | off (with switch set for PBE) | BEN: Parental leave benefit \n", "15: bpa_se | off (with switch set for PBE) | BEN: Special leave days other parent (10 days) \n", "16: tscee_se | on | SIC: Employee Social Insurance contribution \n", "17: tscer_se | on | SIC: Employer Social Insurance contribution \n", "18: tscse_se | on | SIC: Self-employed Social Insurance contribution \n", "19: tin_se | on | TAX: Personal Income tax \n", "20: tinkt_se | on | TAX: Tax on Capital Income \n", "21: bch_se | on | BEN: Child benefit \n", "22: bho_se | on | BEN: Housing allowance \n", "23: bhope_se | on | BEN: Housing allowance for pensioners \n", "24: bsamt_se | on | BEN: Social Assistance (means-tested) \n", "25: tco_se | off | TAX: Commodities \n", "26: output_std_se | on | DEF: STANDARD OUTPUT INDIVIDUAL LEVEL \n", "27: output_std_hh_se | off | DEF: STANDARD OUTPUT HOUSEHOLD LEVEL " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].systems[\"SE_2021\"].policies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we see that some policies are turned off by default. Note that the behaviour of the policies can be controlled from the connector. We can for example switch the policy bunct_se to on. Let us first look at the policy" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "PolicyInSystem\n", "------------------------------\n", "\t ID: 'bde78132-3f44-4d2e-a1ea-4849f88c27766B7D3970-7A4E-4BAC-BBB1-43ABBD3C989A'\n", "\t comment: 'BEN: Housing allowance'\n", "\t extensions: 0 elements\n", "\t functions: 18 elements\n", "\t name: 'bho_se'\n", "\t order: '23'\n", "\t polID: '6B7D3970-7A4E-4BAC-BBB1-43ABBD3C989A'\n", "\t private: 'no'\n", "\t spineOrder: '23'\n", "\t switch: 'on'\n", "\t sysID: 'bde78132-3f44-4d2e-a1ea-4849f88c2776'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].systems[\"SE_2021\"].policies[22]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We see here that there is this attribute `switch` that is part of the `PolicyInSystem` class. This attribute, similar to attribute is modifiable and the changes that you will make will be passed to the EUROMOD software when simulating. Changes implemented during your Python session are however not lasting. For now, when making lasting changes to the model, one should implement them via the User Interface of EUROMOD. Note that the python connector is not checking what kind of modifications you make to the model. Changing attributes like ID's are definitely not adviseable. " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Simulation for system SE_2021 with dataset SE_2022_b1 finished.\n" ] }, { "data": { "text/plain": [ "-10.688592026232982" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].systems[\"SE_2021\"].policies[13].switch = 'on'\n", "out_with_bunct_se = mod.countries[\"SE\"].systems[\"SE_2021\"].run(data,\"SE_2022_b1\")\n", "# Here we see that the average benefit, which is represented by ils_ben, is indeed larger by switching on the bunct_se policy.\n", "out_baseline.outputs[0].ils_ben.mean() - out_with_bunct_se.outputs[0].ils_ben.mean()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0: setdefault_se | on | DEF: SET DEFAULT \n", "1: uprate_se | on | DEF: UPRATING FACTORS \n", "2: ConstDef_se | on | DEF: CONSTANTS \n", "3: IlsDef_se | on | DEF: INCOME CONCEPTS (standardized) \n", "4: IlsUDBdef_se | on | DEF: INCOME CONCEPTS (UDB) \n", "5: ildef_se | on | DEF: INCOME CONCEPTS (non-standardized) \n", "6: random_se | on | DEF: Random assignment \n", "7: TransLMA_se | off | DEF: Modelling labour market transitions (DO NOT S ... \n", "8: tudef_se | on | DEF: ASSESSMENT UNITS \n", "9: yem_se | off (with switch set for MWA) | DEF: minimum wage \n", "10: neg_se | on | DEF: recode negative self-employment income to zer ... \n", "11: yemcomp_se | on | BEN: wage compensation scheme COVID-19 (ONLY WORK ... \n", "12: hhot_switch_se | on (with switch set for HHoT_un, WEB) | DEF: switch on bunct for HHoT extension \n", "13: bunct_se | on | BEN: unemployment benefit (contributory) \n", "14: bfapl_se | off (with switch set for PBE) | BEN: Parental leave benefit \n", "15: bpa_se | off (with switch set for PBE) | BEN: Special leave days other parent (10 days) \n", "16: tscee_se | on | SIC: Employee Social Insurance contribution \n", "17: tscer_se | on | SIC: Employer Social Insurance contribution \n", "18: tscse_se | on | SIC: Self-employed Social Insurance contribution \n", "19: tin_se | on | TAX: Personal Income tax \n", "20: tinkt_se | on | TAX: Tax on Capital Income \n", "21: bch_se | on | BEN: Child benefit \n", "22: bho_se | on | BEN: Housing allowance \n", "23: bhope_se | on | BEN: Housing allowance for pensioners \n", "24: bsamt_se | on | BEN: Social Assistance (means-tested) \n", "25: tco_se | off | TAX: Commodities \n", "26: output_std_se | on | DEF: STANDARD OUTPUT INDIVIDUAL LEVEL \n", "27: output_std_hh_se | off | DEF: STANDARD OUTPUT HOUSEHOLD LEVEL " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].systems[\"SE_2021\"].policies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As mentioned earlier, the connector mimicks the hierarchical structure of the UI. Hence, the definition of functions and parameters are defined on the country level, and their actual implementation are here also accessible via the Tax System. Note that also here, the values of a parameter and the switch of a function can be manipulated through the Python Connector without saving the changes permanently." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0: ArithOp | Wealth to be included in the means \n", "1: Allocate | Allocation of wealth to the partners \n", "2: BenCalc | Income of children is not take into account in the ... \n", "3: BenCalc | Families with children - Special component \n", "4: BenCalc | Families with children - Rent component \n", "5: BenCalc | Families with children - Reduction for each partne ... \n", "6: BenCalc | Families with children - Reduction for each partne ... \n", "7: BenCalc | Families with children - Final allowance after red ... \n", "8: ArithOp | Families with children - 25% increase in 2nd half ... \n", "9: BenCalc | Families with children - Lone parents - Reduction \n", "10: ArithOp | Families with children - Lone parents - 25% increa ... \n", "11: Elig | Young families without children \n", "12: BenCalc | Young families without children - Rent component \n", "13: BenCalc | Young families without children - Single - Reducti ... \n", "14: BenCalc | Young families without children - Reduction for ea ... \n", "15: BenCalc | Young families without children - Reduction for ea ... \n", "16: BenCalc | Young families without children - With partner Red ... \n", "17: BenCalc | Housing allowance \n", "\n", "0: ArithOp | on | Wealth to be included in the means \n", "1: Allocate | on | Allocation of wealth to the partners \n", "2: BenCalc | on | Income of children is not take into account in the ... \n", "3: BenCalc | on | Families with children - Special component \n", "4: BenCalc | on | Families with children - Rent component \n", "5: BenCalc | on | Families with children - Reduction for each partne ... \n", "6: BenCalc | on | Families with children - Reduction for each partne ... \n", "7: BenCalc | on | Families with children - Final allowance after red ... \n", "8: ArithOp | on | Families with children - 25% increase in 2nd half ... \n", "9: BenCalc | on | Families with children - Lone parents - Reduction \n", "10: ArithOp | on | Families with children - Lone parents - 25% increa ... \n", "11: Elig | on | Young families without children \n", "12: BenCalc | on | Young families without children - Rent component \n", "13: BenCalc | on | Young families without children - Single - Reducti ... \n", "14: BenCalc | on | Young families without children - Reduction for ea ... \n", "15: BenCalc | on | Young families without children - Reduction for ea ... \n", "16: BenCalc | on | Young families without children - With partner Red ... \n", "17: BenCalc | on | Housing allowance \n", "\n" ] } ], "source": [ "# Overview of the functions defined in the bho_se policy\n", "print(mod.countries[\"SE\"].policies[22].functions)\n", "# System specific Implementation of functions\n", "print(mod.countries[\"SE\"].systems[\"SE_2021\"].policies[22].functions)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0: formula | only 15% of wealth exceeding the amount \n", "1: #_amount | \"This is the wealth threshold, expressed as \"\"mont ... \n", "2: output_var | Wealth to be included in the means \n", "3: TAX_UNIT | \n", "\n", "0: formula | 0.15*max(afc-amount#1,0) | only 15% of wealth exceeding the amount \n", "1: #_amount | 100000#y | \"This is the wealth threshold, expressed as \"\"mont ... \n", "2: output_var | afc00_s | Wealth to be included in the means \n", "3: TAX_UNIT | tu_bho_se | \n", "\n" ] } ], "source": [ "# Overview of the parameters defined in the bho_se policy\n", "print(mod.countries[\"SE\"].policies[22].functions[0].parameters)\n", "# Implementation of parameters\n", "print(mod.countries[\"SE\"].systems[\"SE_2021\"].policies[22].functions[0].parameters)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Other Important EUROMOD Objects\n", "Central to the EUROMOD project, next to the coding of the policies is the microdata. How datasets should be treated by the model is configured in the model already. The attributes of the datasets are just like the spine-elements accessible and modifiable." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0: SE_2007_a4 \n", "1: SE_2008_a3 \n", "2: training_data \n", "3: SE_2010_a1 \n", "4: SE_2012_a2 \n", "5: SE_2015_a1 \n", "6: SE_2009_hhot \n", "7: SE_2010_hhot \n", "8: SE_2011_hhot \n", "9: SE_2012_hhot \n", "10: SE_2013_hhot \n", "11: SE_2014_hhot \n", "12: SE_2015_hhot \n", "13: SE_2016_hhot \n", "14: SE_2017_hhot \n", "15: SE_2016_a1 \n", "16: SE_2018_hhot \n", "17: SE_2019_hhot \n", "18: SE_2018_a2 \n", "19: SE_2017_a3 \n", "20: SE_2020_hhot \n", "21: SE_2010_a1_2010_03_e1\n", "22: SE_2019_a1 \n", "23: SE_2020_b1 \n", "24: SE_2021_hhot \n", "25: SE_2022_hhot \n", "26: SE_2015_a1_2015_03_e2\n", "27: SE_2021_b1 \n", "28: SE_2023_hhot \n", "29: SE_2022_b1 \n", "30: SE_2019_a1_2015_03_e2\n", "31: SE_2020_b1_2015_03_e2\n", "32: SE_2021_b1_2015_03_e2\n", "33: SE_2022_b1_2015_03_e2\n", "34: SE_training_data \n", "35: SE_2024_hhot " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].datasets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the previous section we used SE_2022_b1. Let us have a look at it." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "Dataset\n", "------------------------------\n", "\t ID: 'f22d52a2-acfe-41c6-852a-e1eaa1540566'\n", "\t coicopVersion: ''\n", "\t comment: ''\n", "\t currency: 'national'\n", "\t decimalSign: '.'\n", "\t name: 'SE_2022_b1'\n", "\t private: 'no'\n", "\t readXVariables: 'no'\n", "\t system_elements: 0 elements\n", "\t useCommonDefault: 'no'\n", "\t yearCollection: '2022'\n", "\t yearInc: '2021'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].datasets[\"SE_2022_b1\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similar to policies, functions and parameters, can the attributes of the policies be modified here. An other important concept in euromod are extensions and are defined globally on the `Model` level or locally on the `Country` level. " ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "Extension\n", "------------------------------\n", "\t ID: '557c232a-9ce6-4808-b52f-ca5e02fe8cf4'\n", "\t look: '|BUTTON_COLOR=-16744384|'\n", "\t name: 'Minimum Wage Adjustments'\n", "\t shortName: 'MWA'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].extensions[7]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `extensions` object is of the type `Container`, which means that you can index it by the number preceding their name. If we want to access the information stored in the Minimum Wage Adjustments extension for example, one can simply use the following command. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Displaying information about a dataset relative to a system, e.g. dataset 'sl_demo_v4' for the system 'SL_1996', by indexing the attribute `datasets`:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "------------------------------\n", "DatasetInSystem\n", "------------------------------\n", "\t ID: 'F7E5CACE-CECC-4BB6-9841-A936D0975481CBA7E428-F8E4-4CEB-8A5E-9ACE73987DD7'\n", "\t bestMatch: 'no'\n", "\t coicopVersion: ''\n", "\t comment: ''\n", "\t currency: 'euro'\n", "\t dataID: 'CBA7E428-F8E4-4CEB-8A5E-9ACE73987DD7'\n", "\t decimalSign: '.'\n", "\t name: 'sl_demo_v4'\n", "\t private: 'no'\n", "\t readXVariables: 'no'\n", "\t sysID: 'F7E5CACE-CECC-4BB6-9841-A936D0975481'\n", "\t useCommonDefault: 'no'" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries['SL'].systems['SL_1996'].datasets[0]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 4 }