Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Sep 18, 2024
1 parent 0d047f3 commit e8b001e
Show file tree
Hide file tree
Showing 8 changed files with 5,926 additions and 5,836 deletions.
38 changes: 28 additions & 10 deletions docs/book/model/baseline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"OBR_PSND = [2_540, 2_691, 2_793, 2_820, 2_903, 2_995, 3_078]\n",
"from policyengine_uk_data.storage import STORAGE_FOLDER\n",
"import pandas as pd\n",
"\n",
"tax_ben = pd.read_csv(STORAGE_FOLDER / \"tax_benefit.csv\")\n",
"REVENUES = [\n",
" \"income_tax\",\n",
Expand All @@ -54,9 +55,14 @@
" \"pip\",\n",
" \"dla\",\n",
"]\n",
"tax_ben_revenues = tax_ben[tax_ben.name.isin(REVENUES)].set_index(\"name\").loc[REVENUES]\n",
"tax_ben_spending = tax_ben[tax_ben.name.isin(SPENDING)].set_index(\"name\").loc[SPENDING]\n",
"tax_ben_revenues = (\n",
" tax_ben[tax_ben.name.isin(REVENUES)].set_index(\"name\").loc[REVENUES]\n",
")\n",
"tax_ben_spending = (\n",
" tax_ben[tax_ben.name.isin(SPENDING)].set_index(\"name\").loc[SPENDING]\n",
")\n",
"from policyengine_uk import Microsimulation\n",
"\n",
"PE_REVENUES = [\n",
" \"income_tax\",\n",
" \"ni_employee\",\n",
Expand All @@ -78,17 +84,29 @@
"\n",
"for year in range(2022, 2029):\n",
" obr_psnd = OBR_PSND[year - 2022]\n",
" obr_totals = tax_ben_spending[str(year)].sum() - tax_ben_revenues[str(year)].sum()\n",
" pe_revenues = sum(baseline.calculate(variable, map_to=\"household\", period=year).sum()/1e9 for variable in PE_REVENUES)\n",
" pe_spending = sum(baseline.calculate(variable, map_to=\"household\", period=year).sum()/1e9 for variable in PE_SPENDING)\n",
" obr_totals = (\n",
" tax_ben_spending[str(year)].sum() - tax_ben_revenues[str(year)].sum()\n",
" )\n",
" pe_revenues = sum(\n",
" baseline.calculate(variable, map_to=\"household\", period=year).sum()\n",
" / 1e9\n",
" for variable in PE_REVENUES\n",
" )\n",
" pe_spending = sum(\n",
" baseline.calculate(variable, map_to=\"household\", period=year).sum()\n",
" / 1e9\n",
" for variable in PE_SPENDING\n",
" )\n",
" pe_totals = pe_spending - pe_revenues\n",
" pe_psnd.append(obr_psnd + pe_totals - obr_totals)\n",
"\n",
"df = pd.DataFrame({\n",
" \"year\": range(2022, 2029),\n",
" \"OBR\": OBR_PSND,\n",
" \"PE\": pe_psnd,\n",
"})"
"df = pd.DataFrame(\n",
" {\n",
" \"year\": range(2022, 2029),\n",
" \"OBR\": OBR_PSND,\n",
" \"PE\": pe_psnd,\n",
" }\n",
")"
]
},
{
Expand Down
58 changes: 34 additions & 24 deletions docs/book/programs/gov/dwp/PIP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,18 @@
"enhanced_daily = parameters.gov.dwp.pip.daily_living.enhanced\n",
"standard_daily = parameters.gov.dwp.pip.daily_living.standard\n",
"\n",
"elements = [enhanced_daily, standard_daily] # [...]\n",
"elements = [enhanced_daily, standard_daily] # [...]\n",
"\n",
"dates = [\"2016-01-01\",\"2017-01-01\",\"2018-01-01\",\"2019-01-01\",\"2020-01-01\", \"2021-01-01\", \"2022-01-01\",\"2023-01-01\"]\n",
"dates = [\n",
" \"2016-01-01\",\n",
" \"2017-01-01\",\n",
" \"2018-01-01\",\n",
" \"2019-01-01\",\n",
" \"2020-01-01\",\n",
" \"2021-01-01\",\n",
" \"2022-01-01\",\n",
" \"2023-01-01\",\n",
"]\n",
"names = [\"enhanced\", \"standard\"]\n",
"\n",
"import pandas as pd\n",
Expand All @@ -174,18 +183,14 @@
"for date in dates:\n",
" for element, name in zip(elements, names):\n",
" # Append to a dataframe: row = date, column = element, value = amount\n",
" new_row = {\n",
" \"date\": date,\n",
" \"element\": name,\n",
" \"amount\": element(date)\n",
" }\n",
" # Append row to the dataframe\n",
" new_row = {\"date\": date, \"element\": name, \"amount\": element(date)}\n",
" # Append row to the dataframe\n",
" df = pd.concat([df, pd.DataFrame([new_row])])\n",
"\n",
"\n",
"# merge element cells\n",
"pivot_df = df.pivot(index=\"date\", columns=\"element\", values=\"amount\")\n",
"pivot_df.fillna(\"\")\n"
"pivot_df.fillna(\"\")"
]
},
{
Expand Down Expand Up @@ -1234,9 +1239,9 @@
" yaxis_range=[0, 100],\n",
" yaxis_tickformat=\",.0f\",\n",
" yaxis_tickprefix=\"£\",\n",
" yaxis_title = \"Amount(£m)\",\n",
" xaxis_title = \"Year\",\n",
" legend_title = \"Element\"\n",
" yaxis_title=\"Amount(£m)\",\n",
" xaxis_title=\"Year\",\n",
" legend_title=\"Element\",\n",
")\n",
"\n",
"fig = format_fig(fig)\n",
Expand Down Expand Up @@ -1374,9 +1379,18 @@
"enhanced_mobility = parameters.gov.dwp.pip.mobility.enhanced\n",
"standard_mobility = parameters.gov.dwp.pip.mobility.standard\n",
"\n",
"elements = [enhanced_mobility, standard_mobility] # [...]\n",
"elements = [enhanced_mobility, standard_mobility] # [...]\n",
"\n",
"dates = [\"2016-01-01\",\"2017-01-01\",\"2018-01-01\",\"2019-01-01\",\"2020-01-01\", \"2021-01-01\", \"2022-01-01\",\"2023-01-01\"]\n",
"dates = [\n",
" \"2016-01-01\",\n",
" \"2017-01-01\",\n",
" \"2018-01-01\",\n",
" \"2019-01-01\",\n",
" \"2020-01-01\",\n",
" \"2021-01-01\",\n",
" \"2022-01-01\",\n",
" \"2023-01-01\",\n",
"]\n",
"names = [\"enhanced\", \"standard\"]\n",
"\n",
"import pandas as pd\n",
Expand All @@ -1386,18 +1400,14 @@
"for date in dates:\n",
" for element, name in zip(elements, names):\n",
" # Append to a dataframe: row = date, column = element, value = amount\n",
" new_row = {\n",
" \"date\": date,\n",
" \"element\": name,\n",
" \"amount\": element(date)\n",
" }\n",
" # Append row to the dataframe\n",
" new_row = {\"date\": date, \"element\": name, \"amount\": element(date)}\n",
" # Append row to the dataframe\n",
" df = pd.concat([df, pd.DataFrame([new_row])])\n",
"\n",
"\n",
"# merge element cells\n",
"pivot_df = df.pivot(index=\"date\", columns=\"element\", values=\"amount\")\n",
"pivot_df.fillna(\"\")\n"
"pivot_df.fillna(\"\")"
]
},
{
Expand Down Expand Up @@ -2417,9 +2427,9 @@
" yaxis_range=[0, 100],\n",
" yaxis_tickformat=\",.0f\",\n",
" yaxis_tickprefix=\"£\",\n",
" yaxis_title = \"Amount(£m)\",\n",
" xaxis_title = \"Year\",\n",
" legend_title = \"Element\"\n",
" yaxis_title=\"Amount(£m)\",\n",
" xaxis_title=\"Year\",\n",
" legend_title=\"Element\",\n",
")\n",
"\n",
"fig = format_fig(fig)\n",
Expand Down
100 changes: 67 additions & 33 deletions docs/book/programs/gov/dwp/pension-credit.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit e8b001e

Please sign in to comment.