Skip to content

Commit

Permalink
Merge pull request #946 from PolicyEngine/data-migrate
Browse files Browse the repository at this point in the history
Migrate to policyengine-uk-data
  • Loading branch information
nikhilwoodruff authored Sep 18, 2024
2 parents 478f935 + fa80b6b commit b8e7ca1
Show file tree
Hide file tree
Showing 97 changed files with 488 additions and 10,491 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ jobs:
with:
args: ". -l 79 --check"
Test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -34,7 +31,6 @@ jobs:
env:
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN}}
- name: Generate documentation
if: matrix.os == 'ubuntu-latest'
run: make documentation
env:
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN}}
13 changes: 1 addition & 12 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ on:
jobs:
Lint:
runs-on: ubuntu-latest
if: |
(github.repository == 'PolicyEngine/policyengine-uk')
steps:
- uses: actions/checkout@v2
- name: Check formatting
uses: "lgeiger/black-action@master"
with:
args: ". -l 79 --check"
Test:
runs-on: ${{ matrix.os }}
if: |
(github.repository == 'PolicyEngine/policyengine-uk')
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -48,8 +41,6 @@ jobs:
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: docs/book/_build/html # The folder the action should deploy.
Publish:
if: |
(github.repository == 'PolicyEngine/policyengine-uk')
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand All @@ -69,8 +60,6 @@ jobs:
password: ${{ secrets.PYPI }}
skip_existing: true
Deploy:
if: |
(github.repository == 'PolicyEngine/policyengine-uk')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB }}
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,4 @@ policyengine_uk/calibration/*.h5
**/*.csv
**/*.pkl
**/*.log
**/ukmod.json
*.ipynb

!test9.ipynb
**/ukmod.json
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test:
documentation:
jb clean docs/book
jb build docs/book
python policyengine_uk/tools/add_plotly_to_book.py docs/book/_build
python docs/book/add_plotly_to_book.py docs/book/_build

changelog:
build-changelog changelog.yaml --output changelog.yaml --update-last-date --start-from 0.1.0 --append-file changelog_entry.yaml
Expand Down
5 changes: 3 additions & 2 deletions docs/book/_config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
title: PolicyEngine UK documentation
author: PolicyEngine
copyright: "2022"
copyright: "2024"
logo: logo.png

execute:
execute_notebooks: force
execute_notebooks: off

repository:
url: https://github.com/policyengine/policyengine-uk
Expand Down
7 changes: 0 additions & 7 deletions docs/book/_static/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto+Serif:[email protected]&family=Roboto:wght@300&display=swap');

h1, h2, h3, h4, h5, h6 {
font-family: "Roboto";
}

body {
font-family: "Roboto Serif";
}
14 changes: 10 additions & 4 deletions docs/book/_toc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
format: jb-book
root: index
parts:
- caption: Using the model
chapters:
- file: usage/getting-started
- file: usage/income-sources
- caption: Model
chapters:
- file: model/baseline
- caption: Validation
chapters:
- file: validation/spi-validation
- caption: Programs
chapters:
- file: programs/gov/hmrc/child-benefit
Expand All @@ -16,7 +26,3 @@ parts:
- file: programs/gov/dcms/bbc/tv-licence
- file: programs/gov/revenue_scotland/land-and-buildings-transaction-tax
- file: programs/gov/wra/land-transaction-tax
- file: model/spi-validation
- caption: Using the model
chapters:
- file: usage/getting-started
File renamed without changes.
245 changes: 245 additions & 0 deletions docs/book/model/baseline.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Baseline forecast\n",
"\n",
"To anchor PolicyEngine to official forecasts, this page presents both the Office for Budget Responsibility (OBR)'s forecast for public sector net debt (PSND) and that implied by PolicyEngine.\n",
"\n",
"PSND is generally used as the key fiscal metric in the UK, and all talk of 'headroom' and 'cost' of fiscal measures is in relation to this metric. In calculating PolicyEngine's projection for PSND, we use the OBR's forecast and subtract the cost and revenue projections for benefits modelled in PolicyEngine:\n",
"\n",
"* Income Tax\n",
"* National Insurance (all classes)\n",
"* VAT\n",
"* Stamp Duty Land Tax\n",
"* Fuel duties\n",
"* Universal Credit\n",
"* Child Benefit\n",
"* Working Tax Credit\n",
"* Child Tax Credit\n",
"* Housing Benefit\n",
"* Personal Independence Payment\n",
"* Disability Living Allowance\n",
"* TV Licence"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"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",
"tax_ben = pd.read_csv(STORAGE_FOLDER / \"tax_benefit.csv\")\n",
"REVENUES = [\n",
" \"income_tax\",\n",
" \"ni_employee\",\n",
" \"ni_employer\",\n",
" \"vat\",\n",
" \"fuel_duties\",\n",
" \"tv_licence_fee\",\n",
"]\n",
"SPENDING = [\n",
" \"universal_credit\",\n",
" \"tax_credits\",\n",
" \"housing_benefit\",\n",
" \"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",
"from policyengine_uk import Microsimulation\n",
"PE_REVENUES = [\n",
" \"income_tax\",\n",
" \"ni_employee\",\n",
" \"ni_employer\",\n",
" \"vat\",\n",
" \"fuel_duty\",\n",
" \"tv_licence\",\n",
"]\n",
"PE_SPENDING = [\n",
" \"universal_credit\",\n",
" \"tax_credits\",\n",
" \"housing_benefit\",\n",
" \"pip\",\n",
" \"dla\",\n",
"]\n",
"baseline = Microsimulation()\n",
"\n",
"pe_psnd = []\n",
"\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",
" 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",
"})"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>year</th>\n",
" <th>OBR</th>\n",
" <th>PE</th>\n",
" <th>diff</th>\n",
" <th>diff_pct</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2022</td>\n",
" <td>2540</td>\n",
" <td>2538.0</td>\n",
" <td>-1.5</td>\n",
" <td>-0.001</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2023</td>\n",
" <td>2691</td>\n",
" <td>2693.0</td>\n",
" <td>2.2</td>\n",
" <td>0.001</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2024</td>\n",
" <td>2793</td>\n",
" <td>2800.0</td>\n",
" <td>7.5</td>\n",
" <td>0.003</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2025</td>\n",
" <td>2820</td>\n",
" <td>2831.0</td>\n",
" <td>10.5</td>\n",
" <td>0.004</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2026</td>\n",
" <td>2903</td>\n",
" <td>2915.0</td>\n",
" <td>12.2</td>\n",
" <td>0.004</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>2027</td>\n",
" <td>2995</td>\n",
" <td>3013.0</td>\n",
" <td>18.1</td>\n",
" <td>0.006</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>2028</td>\n",
" <td>3078</td>\n",
" <td>3106.0</td>\n",
" <td>27.8</td>\n",
" <td>0.009</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" year OBR PE diff diff_pct\n",
"0 2022 2540 2538.0 -1.5 -0.001\n",
"1 2023 2691 2693.0 2.2 0.001\n",
"2 2024 2793 2800.0 7.5 0.003\n",
"3 2025 2820 2831.0 10.5 0.004\n",
"4 2026 2903 2915.0 12.2 0.004\n",
"5 2027 2995 3013.0 18.1 0.006\n",
"6 2028 3078 3106.0 27.8 0.009"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[\"diff\"] = df[\"PE\"] - df[\"OBR\"]\n",
"df[\"diff_pct\"] = (df[\"diff\"] / df[\"OBR\"]).round(3)\n",
"df[\"PE\"] = df[\"PE\"].round(0)\n",
"df[\"diff\"] = df[\"diff\"].round(1)\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PolicyEngine appears to predict a higher PSND trend line than the OBR, increasing linearly through to 2028-29. This is over 90% explained by PolicyEngine projecting lower income tax receipts than the OBR. It's unclear why this is the case, and it might not actually be a bug: PolicyEngine optimises household weights to fit targets *including* the income tax targets, as well as income statistics. This could be the model saying that income tax receipts being lower is more consistent with other projections for the UK household sector."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion docs/book/programs/gov/dwp/PIP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "730262ba",
"metadata": {},
"source": [
"# Personal Independence Payment (PIP)\n",
"# PIP\n",
"\n",
"Personal Independence Payment (PIP) is a benefit payment administered by the Department for Work and Pensions (DWP) in the United Kingdom. It is designed to provide financial support to individuals with long-term health conditions or disabilities. PIP helps recipients with the extra costs associated with their condition and is not means-tested.\n",
"PIP is divided into two main components:\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/book/programs/gov/hmrc/fuel-duty.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fuel Duty\n",
"# Fuel duty\n",
"\n",
"Fuel duty is a tax levied on the sale of fuels, mainly petrol and diesel used in vehicles or used for heating. PolicyEngine models fuel duty imposed on the purchases of petrol and diesel for vehicles only.\n",
"\n",
Expand Down
Loading

0 comments on commit b8e7ca1

Please sign in to comment.