Skip to content

Commit

Permalink
Add PSND util
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Sep 17, 2024
1 parent 9ecc9dc commit 4240a3f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 21 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
2 changes: 1 addition & 1 deletion docs/book/add_plotly_to_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
)

with open(html_file, "w") as f:
f.write(html)
f.write(html)
2 changes: 1 addition & 1 deletion policyengine_uk/parameters/gov/dwp/LHA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

lha_list_of_rents = pd.read_csv(
Path(__file__).parent / "lha_list_of_rents.csv.gz"
)
)
2 changes: 1 addition & 1 deletion policyengine_uk/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from policyengine_uk_data.storage import STORAGE_FOLDER
import pandas as pd
from policyengine_uk.tools.parameters import (
from policyengine_uk.utils.parameters import (
backdate_parameters,
convert_to_fiscal_year_parameters,
)
Expand Down
File renamed without changes.
File renamed without changes.
83 changes: 83 additions & 0 deletions policyengine_uk/utils/psnd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import pandas as pd


def project_psnd():
from policyengine_uk_data.storage import STORAGE_FOLDER
from policyengine_uk import Microsimulation

OBR_PSND = [2_540, 2_691, 2_793, 2_820, 2_903, 2_995, 3_078]
tax_ben = pd.read_csv(STORAGE_FOLDER / "tax_benefit.csv")
REVENUES = [
"income_tax",
"ni_employee",
"ni_employer",
"vat",
"fuel_duties",
"tv_licence_fee",
]
SPENDING = [
"universal_credit",
"tax_credits",
"housing_benefit",
"pip",
"dla",
]
tax_ben_revenues = (
tax_ben[tax_ben.name.isin(REVENUES)].set_index("name").loc[REVENUES]
)
tax_ben_spending = (
tax_ben[tax_ben.name.isin(SPENDING)].set_index("name").loc[SPENDING]
)
PE_REVENUES = [
"income_tax",
"ni_employee",
"ni_employer",
"vat",
"fuel_duty",
"tv_licence",
]
PE_SPENDING = [
"universal_credit",
"tax_credits",
"housing_benefit",
"pip",
"dla",
]
baseline = Microsimulation()

pe_psnd = []

for year in range(2022, 2029):
obr_psnd = OBR_PSND[year - 2022]
obr_totals = (
tax_ben_spending[str(year)].sum()
- tax_ben_revenues[str(year)].sum()
)
pe_revenues = sum(
baseline.calculate(variable, map_to="household", period=year).sum()
/ 1e9
for variable in PE_REVENUES
)
pe_spending = sum(
baseline.calculate(variable, map_to="household", period=year).sum()
/ 1e9
for variable in PE_SPENDING
)
pe_totals = pe_spending - pe_revenues
pe_psnd.append(obr_psnd + pe_totals - obr_totals)

df = pd.DataFrame(
{
"year": range(2022, 2029),
"OBR": OBR_PSND,
"PE": pe_psnd,
}
)

df["PE"] = df["PE"].round().astype(int)

df.to_csv("psnd.csv", index=False)


if __name__ == "__main__":
project_psnd()
1 change: 0 additions & 1 deletion policyengine_uk/variables/gov/hmrc/business_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ class business_rates(Variable):
unit = GBP

formula = baseline_business_rates.formula

0 comments on commit 4240a3f

Please sign in to comment.