Expenditure by Function to GDP
Get the Government Expenditure by Function to GDP Ratio for a variety of countries over time from the Government Finance Statistics of the International Monetary Fund (IMF). It is the spending of the general government on each function of the United Nations’ Classification of the Functions of Government (COFOG) as a share of the Gross Domestic Product (GDP).
Shares of GDP make the functions comparable across countries and over time, such as NATO’s 2% of GDP guideline for defence. The ten divisions, the Public Debt Transactions (group 01.7, mostly interest) and the Total are described in get_government_expenditure_by_function. Defence covers military and civil defence, foreign military aid and defence research, not military pensions, so it differs from NATO’s definition and from a national defence budget.
For the interest itself, get_government_interest_expenditure_to_gdp_ratio uses the same general government and the same GDP, so the two together answer whether a government pays more in interest than it spends on defence.
The data is yearly, for around 180 countries; the most recent year is usually one or two years back. The ratio is the IMF’s own figure, published in percent and divided by 100 here, so it is a decimal fraction (0.0311 for 3.11% of GDP).
The formula is as follows:
\[\text{Government Expenditure by Function to GDP Ratio} = \text{Expenditure on the Function} / \text{Nominal GDP}\]Also known as: defence spending to GDP, military spending to GDP, health spending to GDP, education spending to GDP, social spending to GDP, COFOG to GDP.
Expenditure by Function to GDP in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_government_expenditure_by_function_to_gdp_ratio as shown below.
from financetoolkit import Economics
economics = Economics(start_date='2015-01-01', end_date="2025-12-31")
defence = economics.get_government_expenditure_by_function_to_gdp_ratio(
countries=['United States', 'Japan', 'Germany', 'United Kingdom'], functions='Defence')
defence.xs('Defence', axis=1, level='Function')
Or, after setting up the Finance Toolkit MCP, ask:
What was government defence spending as a share of GDP in the United States, Japan, Germany and the United Kingdom in each year from 2015 to 2024?
Which returns:
| United States | Japan | Germany | United Kingdom | |
|---|---|---|---|---|
| 2015 | 0.0327 | 0.0086 | 0.0094 | 0.0198 |
| 2016 | 0.0318 | 0.0079 | 0.0096 | 0.0189 |
| 2017 | 0.0314 | 0.0085 | 0.0099 | 0.0185 |
| 2018 | 0.032 | 0.009 | 0.0105 | 0.0183 |
| 2019 | 0.0331 | 0.0089 | 0.0106 | 0.0196 |
| 2020 | 0.0348 | 0.0092 | 0.0112 | 0.0214 |
| 2021 | 0.0321 | 0.0099 | 0.0114 | 0.0212 |
| 2022 | 0.0298 | 0.0092 | 0.0115 | 0.0214 |
| 2023 | 0.0303 | 0.0105 | 0.0125 | 0.022 |
| 2024 | 0.0311 | 0.013 | 0.0135 | 0.0225 |
Parameters
get_government_expenditure_by_function_to_gdp_ratio 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 COFOG divisions, “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 |