Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pension Credit documentation #772

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
added:
- Pension Credit documentation page.
1 change: 1 addition & 0 deletions docs/book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parts:
chapters:
- file: programs/gov/hmrc/child-benefit
- file: programs/gov/dwp/universal-credit
- file: programs/gov/dwp/pension-credit
- file: programs/gov/hmrc/national-insurance
- file: programs/gov/hmrc/fuel-duty
- file: programs/gov/hmrc/stamp-duty
Expand Down
54 changes: 38 additions & 16 deletions docs/book/examples/income-sources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1152,15 +1152,25 @@
"\n",
"sim = Microsimulation()\n",
"\n",
"is_pensioner_household = (sim.calculate(\"is_SP_age\", map_to=\"household\") > 0) * (sim.calculate(\"is_child\", map_to=\"household\") == 0)\n",
"is_pensioner_household = (\n",
" sim.calculate(\"is_SP_age\", map_to=\"household\") > 0\n",
") * (sim.calculate(\"is_child\", map_to=\"household\") == 0)\n",
"household_benefits = sim.calculate(\"household_benefits\")\n",
"household_pensions = sim.calculate(\"pension_income\", map_to=\"household\")\n",
"household_investment_income = sim.calculate(\"capital_income\", map_to=\"household\")\n",
"household_earnings = sim.calculate(\"employment_income\", map_to=\"household\") + sim.calculate(\"self_employment_income\", map_to=\"household\")\n",
"household_investment_income = sim.calculate(\n",
" \"capital_income\", map_to=\"household\"\n",
")\n",
"household_earnings = sim.calculate(\n",
" \"employment_income\", map_to=\"household\"\n",
") + sim.calculate(\"self_employment_income\", map_to=\"household\")\n",
"total_income = sim.calculate(\"household_market_income\") + household_benefits\n",
"\n",
"equivalised_income = sim.calculate(\"equiv_household_net_income\")[is_pensioner_household]\n",
"household_count_people = sim.calculate(\"people\", map_to=\"household\")[is_pensioner_household]\n",
"equivalised_income = sim.calculate(\"equiv_household_net_income\")[\n",
" is_pensioner_household\n",
"]\n",
"household_count_people = sim.calculate(\"people\", map_to=\"household\")[\n",
" is_pensioner_household\n",
"]\n",
"equivalised_income.weights *= household_count_people.values\n",
"household_income_decile = equivalised_income.decile_rank()\n",
"\n",
Expand All @@ -1183,22 +1193,34 @@
" income_sources.append(income_source)\n",
" income_source_values = income_source_decodes[income_source]\n",
" values.append(\n",
" income_source_values[is_pensioner_household][in_decile].sum() / total_income[is_pensioner_household][in_decile].sum()\n",
" income_source_values[is_pensioner_household][in_decile].sum()\n",
" / total_income[is_pensioner_household][in_decile].sum()\n",
" )\n",
" cumulative_income += income_source_values[is_pensioner_household][in_decile].sum()\n",
" cumulative_income += income_source_values[is_pensioner_household][\n",
" in_decile\n",
" ].sum()\n",
" # Add 'other income'\n",
" deciles.append(decile)\n",
" income_sources.append(\"Other\")\n",
" values.append(1 - cumulative_income / total_income[is_pensioner_household][in_decile].sum())\n",
" values.append(\n",
" 1\n",
" - cumulative_income\n",
" / total_income[is_pensioner_household][in_decile].sum()\n",
" )\n",
"\n",
"df = pd.DataFrame({\n",
" \"Decile\": deciles,\n",
" \"Income source\": income_sources,\n",
" \"Value\": values,\n",
"})\n",
"df = pd.DataFrame(\n",
" {\n",
" \"Decile\": deciles,\n",
" \"Income source\": income_sources,\n",
" \"Value\": values,\n",
" }\n",
")\n",
"\n",
"# Order by state support, other income, pensions, investment, earnings\n",
"df[\"Income source\"] = pd.Categorical(df[\"Income source\"], [\"State support\", \"Other\", \"Pensions\", \"Investment\", \"Earnings\"])\n",
"df[\"Income source\"] = pd.Categorical(\n",
" df[\"Income source\"],\n",
" [\"State support\", \"Other\", \"Pensions\", \"Investment\", \"Earnings\"],\n",
")\n",
"df = df.sort_values([\"Decile\", \"Income source\"], ascending=[True, False])\n",
"\n",
"import plotly.express as px\n",
Expand All @@ -1217,7 +1239,7 @@
" yaxis=dict(\n",
" tickformat=\".0%\",\n",
" title=\"Percentage of income\",\n",
" tickvals=[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, .7, .8, .9, 1],\n",
" tickvals=[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1],\n",
" ),\n",
" xaxis=dict(\n",
" title=\"Income decile\",\n",
Expand All @@ -1228,7 +1250,7 @@
"fig = format_fig(fig).update_layout(\n",
" title=\"Sources of income for pensioner households\",\n",
")\n",
"fig\n"
"fig"
]
}
],
Expand Down
73 changes: 48 additions & 25 deletions docs/book/programs/gov/dcms/bbc/tv-licence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,19 @@
"dcms = system.parameters.gov.dcms\n",
"\n",
"df = pd.DataFrame()\n",
"df['Date'] = [\n",
" parameter.instant_str for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"df[\"Date\"] = [\n",
" parameter.instant_str\n",
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"]\n",
"df['Full TV Licence Fee'] = [\n",
" f'£{parameter.value:.2f}' for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"df[\"Full TV Licence Fee\"] = [\n",
" f\"£{parameter.value:.2f}\"\n",
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"]\n",
"df['Blind TV Licence Fee'] = [\n",
" f'£{0.5 * parameter.value:.2f}' for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"df[\"Blind TV Licence Fee\"] = [\n",
" f\"£{0.5 * parameter.value:.2f}\"\n",
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"]\n",
"df.sort_values('Date').set_index('Date')"
"df.sort_values(\"Date\").set_index(\"Date\")"
]
},
{
Expand Down Expand Up @@ -311,24 +314,29 @@
],
"source": [
"import pandas as pd\n",
"\n",
"# aged discount\n",
"aged_discount = {\n",
" \"Reformed value\": [0, 0.25, 0.50, 0.75],\n",
" \"Current value\": [],\n",
" \"Change against current\": [],\n",
" \"Tax revenues impact (£m)\": [91.7, 68.8, 45.9, 22.9],\n",
" \"Reference\": []\n",
" \"Reference\": [],\n",
"}\n",
"reference_list_ad = [\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27903&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27083&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=19090&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27909&region=uk&timePeriod=2023&baseline=1\"\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27909&region=uk&timePeriod=2023&baseline=1\",\n",
"]\n",
"for i in range(len(aged_discount[\"Reformed value\"])):\n",
" aged_discount[\"Current value\"] += [\"100%\"]\n",
" aged_discount[\"Change against current\"] += [f\"{aged_discount['Reformed value'][i]-1:.0%}\"]\n",
" aged_discount[\"Reformed value\"][i] = f\"{aged_discount['Reformed value'][i]:.0%}\"\n",
" aged_discount[\"Change against current\"] += [\n",
" f\"{aged_discount['Reformed value'][i]-1:.0%}\"\n",
" ]\n",
" aged_discount[\"Reformed value\"][\n",
" i\n",
" ] = f\"{aged_discount['Reformed value'][i]:.0%}\"\n",
" aged_discount[\"Reference\"] += [\n",
" f\"<a href=\\\"{reference_list_ad[i]}\\\">Budgetary impact of changing aged discount to {aged_discount['Reformed value'][i]}</a>\"\n",
" ]\n",
Expand All @@ -337,14 +345,25 @@
"df_aged_discount[\"Reformed policy\"] = \"Aged discount\"\n",
"\n",
"# minimum age\n",
"age_list = list(range(70,81))\n",
"age_list = list(range(70, 81))\n",
"age_list.remove(75)\n",
"min_age = {\n",
" \"Reformed value\": age_list,\n",
" \"Current value\": [],\n",
" \"Change against current\": [],\n",
" \"Tax revenues impact (£m)\": [-19.6, -11.4, -7.7, -2.4, -1.5, 1.3, 2.2, 3.7, 7.1, 91.7],\n",
" \"Reference\": []\n",
" \"Tax revenues impact (£m)\": [\n",
" -19.6,\n",
" -11.4,\n",
" -7.7,\n",
" -2.4,\n",
" -1.5,\n",
" 1.3,\n",
" 2.2,\n",
" 3.7,\n",
" 7.1,\n",
" 91.7,\n",
" ],\n",
" \"Reference\": [],\n",
"}\n",
"reference_list_minage = [\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27932&region=uk&timePeriod=2023&baseline=1\",\n",
Expand All @@ -356,13 +375,13 @@
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27951&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27953&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27955&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27960&region=uk&timePeriod=2023&baseline=1\"\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27960&region=uk&timePeriod=2023&baseline=1\",\n",
"]\n",
"for i in range(len(min_age[\"Reformed value\"])):\n",
" min_age[\"Current value\"] += [75]\n",
" min_age[\"Change against current\"] += [min_age[\"Reformed value\"][i] - 75]\n",
" min_age[\"Reference\"] += [\n",
" f\"<a href=\\\"{reference_list_minage[i]}\\\">Budgetary impact of changing minimum age for aged discount to {age_list[i]}</a>\"\n",
" f'<a href=\"{reference_list_minage[i]}\">Budgetary impact of changing minimum age for aged discount to {age_list[i]}</a>'\n",
" ]\n",
"\n",
"df_min_age = pd.DataFrame(min_age)\n",
Expand All @@ -372,32 +391,36 @@
"fee_list = list(range(157, 162))\n",
"fee_list.remove(159)\n",
"licence_fee = {\n",
" \"Reformed value\": fee_list,\n",
" \"Current value\": [],\n",
" \"Change against current\": [],\n",
" \"Tax revenues impact (£m)\": [-52.1, -26, 26, 52.1],\n",
" \"Reference\": []\n",
" \"Reformed value\": fee_list,\n",
" \"Current value\": [],\n",
" \"Change against current\": [],\n",
" \"Tax revenues impact (£m)\": [-52.1, -26, 26, 52.1],\n",
" \"Reference\": [],\n",
"}\n",
"reference_list_fee = [\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27089&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=27087&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=26981&region=uk&timePeriod=2023&baseline=1\",\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=26983&region=uk&timePeriod=2023&baseline=1\"\n",
" \"https://policyengine.org/uk/policy?focus=policyOutput.netIncome&reform=26983&region=uk&timePeriod=2023&baseline=1\",\n",
"]\n",
"for i in range(len(licence_fee[\"Reformed value\"])):\n",
" licence_fee[\"Current value\"] += [\"£159\"]\n",
" licence_fee[\"Change against current\"] += [f\"£{licence_fee['Reformed value'][i]-159}\"]\n",
" licence_fee[\"Change against current\"] += [\n",
" f\"£{licence_fee['Reformed value'][i]-159}\"\n",
" ]\n",
" licence_fee[\"Reformed value\"][i] = f\"£{licence_fee['Reformed value'][i]}\"\n",
" licence_fee[\"Reference\"] += [\n",
" f\"<a href=\\\"{reference_list_fee[i]}\\\">Budgetary impact of changing licence fee to {licence_fee['Reformed value'][i]}</a>\"\n",
" ]\n",
"\n",
"df_licence_fee =pd.DataFrame(licence_fee)\n",
"df_licence_fee = pd.DataFrame(licence_fee)\n",
"df_licence_fee[\"Reformed policy\"] = \"TV licence fee\"\n",
"\n",
"# concat df\n",
"df_reform = pd.concat([df_aged_discount, df_min_age, df_licence_fee])\n",
"df_reform.set_index([\"Reformed policy\", \"Current value\", \"Reformed value\"]).style.format(lambda x: x)\n"
"df_reform.set_index(\n",
" [\"Reformed policy\", \"Current value\", \"Reformed value\"]\n",
").style.format(lambda x: x)"
]
}
],
Expand Down
Loading
Loading