{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Examples\n", "\n", "## Loading and navigating the model\n", "We start with importing the euromod package and creating a `Model` object from a EUROMOD model." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:42.165860Z", "iopub.status.busy": "2026-01-13T11:36:42.165860Z", "iopub.status.idle": "2026-01-13T11:36:46.236659Z", "shell.execute_reply": "2026-01-13T11:36:46.236659Z" } }, "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": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from euromod import Model\n", "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", "The countries and extensions attributes say that they contain elements. If we take a look at countries" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:46.307653Z", "iopub.status.busy": "2026-01-13T11:36:46.299572Z", "iopub.status.idle": "2026-01-13T11:36:46.368912Z", "shell.execute_reply": "2026-01-13T11:36:46.368912Z" } }, "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": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries" ] }, { "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": 3, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:46.368912Z", "iopub.status.busy": "2026-01-13T11:36:46.368912Z", "iopub.status.idle": "2026-01-13T11:36:48.500834Z", "shell.execute_reply": "2026-01-13T11:36:48.500834Z" } }, "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": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"]" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Here we see again an informative representation of the `Country` object, which contains several attributes that can be accessed. We can for example take a look at the first 10 policies that are stored in the country." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:48.509220Z", "iopub.status.busy": "2026-01-13T11:36:48.500834Z", "iopub.status.idle": "2026-01-13T11:36:48.751034Z", "shell.execute_reply": "2026-01-13T11:36:48.751034Z" } }, "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 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].policies[0:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running a system with default configuration\n", "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." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:48.751034Z", "iopub.status.busy": "2026-01-13T11:36:48.751034Z", "iopub.status.idle": "2026-01-13T11:36:48.821662Z", "shell.execute_reply": "2026-01-13T11:36:48.821662Z" } }, "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": [ "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." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:48.821662Z", "iopub.status.busy": "2026-01-13T11:36:48.821662Z", "iopub.status.idle": "2026-01-13T11:36:49.059872Z", "shell.execute_reply": "2026-01-13T11:36:49.059872Z" } }, "outputs": [ { "data": { "text/plain": [ "0: training_data | \n", "1: SE_2010_a1_2010_03_e1 | \n", "2: SE_2019_a1 | \n", "3: SE_2020_b1 | \n", "4: SE_2021_hhot | \n", "5: SE_2015_a1_2015_03_e2 | \n", "6: SE_2021_b1 | \n", "7: SE_2022_b1 | best match \n", "8: SE_2019_a1_2015_03_e2 | \n", "9: SE_2020_b1_2015_03_e2 | \n", "10: SE_2021_b1_2015_03_e2 | \n", "11: SE_2022_b1_2015_03_e2 | \n", "12: SE_training_data | " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod.countries[\"SE\"].systems[\"SE_2021\"].datasets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we see that there are multiple datasets configured, but that PL_2020_b2 is seen as the best match dataset for this taxsystem. Provided that you have the microdata stored somewhere, you can then load it as a `pandas.DataFrame` and run the model in the following way:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:49.059872Z", "iopub.status.busy": "2026-01-13T11:36:49.059872Z", "iopub.status.idle": "2026-01-13T11:36:55.653453Z", "shell.execute_reply": "2026-01-13T11:36:55.653453Z" } }, "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": 7, "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 = mod.countries[\"SE\"].systems[\"SE_2021\"].run(data,\"SE_2022_b1\")\n", "out" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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": 8, "metadata": { "execution": { "iopub.execute_input": "2026-01-13T11:36:55.653453Z", "iopub.status.busy": "2026-01-13T11:36:55.653453Z", "iopub.status.idle": "2026-01-13T11:36:55.919854Z", "shell.execute_reply": "2026-01-13T11:36:55.919854Z" } }, "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", "