Expenditure by Function (COFOG)
Get the Government Expenditure by Function for a variety of countries over time from the Government Finance Statistics of the International Monetary Fund (IMF). The spending of the general government (the central, state and local governments and the social security funds together) is split by purpose according to the United Nations’ Classification of the Functions of Government (COFOG), the classification Eurostat, the OECD and the IMF all publish.
The ten COFOG divisions are General Public Services, Defence, Public Order and Safety, Economic Affairs, Environmental Protection, Housing and Community Amenities, Health, Recreation, Culture and Religion, Education and Social Protection, which add up to the Total. General Public Services include the Public Debt Transactions (group 01.7), which are mostly the interest on government debt, also available as a function of its own where a country reports it. Defence is military and civil defence, foreign military aid and defence research; military pensions are Social Protection.
The data is yearly, in millions of national currency, for around 180 countries; the most recent year is usually one or two years back. Levels are not comparable across countries with different currencies, but growth rates are, and get_government_expenditure_by_function_to_gdp_ratio returns the shares of GDP.
The columns are a country and a function each; a country without data for a function has no column for it, and countries without data are left out with a warning.
Data comes from the IMF’s Government Finance Statistics, further information can be found within https://data.imf.org/en/datasets/IMF.STA:GFS_COFOG
Also known as: COFOG, government spending by function, defence spending, military spending, health spending, education spending, social spending.
Expenditure by Function (COFOG) in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_government_expenditure_by_function as shown below.
from financetoolkit import Economics
economics = Economics(start_date='2018-01-01', end_date="2025-12-31")
expenditure = economics.get_government_expenditure_by_function(
countries=['United States', 'Germany'], functions='Defence,Health,Education')
expenditure['United States']
Or, after setting up the Finance Toolkit MCP, ask:
How much did the US government spend on defence, health and education in each year from 2018 to 2024, in dollars?
Which returns:
| Defence | Health | Education | |
|---|---|---|---|
| 2018 | 660147 | 1.91712e+06 | 1.22016e+06 |
| 2019 | 712831 | 2.0491e+06 | 1.26193e+06 |
| 2020 | 744556 | 2.26781e+06 | 1.28909e+06 |
| 2021 | 762090 | 2.45445e+06 | 1.37456e+06 |
| 2022 | 775165 | 2.64297e+06 | 1.47586e+06 |
| 2023 | 843209 | 2.79374e+06 | 1.54819e+06 |
| 2024 | 911017 | 3.01146e+06 | 1.63922e+06 |
Parameters
get_government_expenditure_by_function accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
countries | list[str] | str | None | A list of countries or a single country to include in the results. Defaults to None. | ["United States", "Germany"] |
functions | list[str] | str | None | The functions to return, a list or a comma-separated string of the ten divisions above, “Public Debt Transactions” or “Total”. Defaults to None, which returns the ten divisions. | None, which returns the ten divisions |
rolling | int | The rolling window size to use for smoothing the data (simple moving average). Defaults to None. | 4 |
trailing | int | The trailing window size to use for summing the data over trailing periods (e.g. a trailing-4-quarter sum). Defaults to None. | 4 |
growth | bool | Whether to return the growth data or the actual data. Defaults to False. | True |
lag | int | The number of periods to lag the growth data. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |