PolicyEngine-UK#

This book contains an introduction to using PolicyEngine-UK to model UK taxes and benefits. It is currently a work in progress and may be added to. PolicyEngine-UK is a microsimulation model of the UK tax and benefit system: it is a model which calculates variable values over UK entities from given policy parameters and structures. In practice, this gives it two main uses: calculating statistics under current tax and benefit law, and simulating effects of potential new changes to the legislation.

We’re grateful to the UKMOD team for publishing descriptions of their model; our ability to reference these descriptions accelerated OpenFisca UK’s development. UKMOD is maintained, developed and managed by the Centre for Microsimulation and Policy Analysis at the Institute for Social and Economic Research (ISER), University of Essex.

Code examples and outputs are re-run automatically on each new version of PolicyEngine-UK.

Short demo#

Baseline estimation#

Calculating, for example, the total tax (Income Tax and National Insurance) liability by region can be done with the following code:

from policyengine_uk import Microsimulation
import pandas as pd

sim = Microsimulation()

df = sim.df(["national_insurance", "income_tax", "people"])

summary = pd.DataFrame(
    df.groupby(sim.calc("region", map_to="person")).sum()
).sort_values(by="people", ascending=False)
summary.national_insurance = summary.national_insurance.apply(
    lambda x: round(x / 1e9, 1)
)
summary.income_tax = summary.income_tax.apply(lambda x: round(x / 1e9, 1))
summary.people = summary.people.apply(lambda x: round(x / 1e6, 1))
summary.columns = [
    "National Insurance (£bn)",
    "Income Tax (£bn)",
    "Population (millions)",
]
summary
National Insurance (£bn) Income Tax (£bn) Population (millions)
SOUTH_EAST 9.6 28.6 9.2
LONDON 10.5 35.5 9.1
NORTH_WEST 6.5 18.2 7.2
EAST_OF_ENGLAND 6.6 25.0 6.3
WEST_MIDLANDS 4.3 9.6 5.9
SOUTH_WEST 5.8 20.4 5.7
YORKSHIRE 4.3 11.3 5.4
SCOTLAND 5.9 13.8 5.3
EAST_MIDLANDS 4.6 14.3 4.8
WALES 2.0 4.5 2.9
NORTH_EAST 2.3 3.9 2.7
NORTHERN_IRELAND 1.3 2.7 1.9

Reform evaluation#

Below is an example of simulating the effects of a reform (namely, increasing the basic rate of income tax from 20% to 23%).

Hide code cell source
from policyengine_uk.model_api import *


def change_tax_parameters(parameters):
    parameters.gov.hmrc.income_tax.rates.uk.brackets[0].rate.update(
        period=periods.period("year:2019:10"), value=0.23
    )
    return parameters


class reform(Reform):
    def apply(self):
        self.modify_parameters(change_tax_parameters)


baseline = Microsimulation()
reformed = Microsimulation(reform=reform)
revenue = reformed.calc("tax").sum() - baseline.calc("tax").sum()
f"Revenue: £{round(revenue / 1e+9, 1)}bn"
'Revenue: £12.1bn'