Government Deficit
Get the Government Deficit for a variety of countries over time from the Global Macro Database (GMDB). Government Deficit is the total amount of money that a government spends more than it collects from taxes and other sources. A government deficit is usually financed by borrowing money.
Data comes from the Global Macro Database (GMDB), further information about the variable can be found within https://www.globalmacrodata.com/documentation.html
The series is signed as a fiscal balance rather than as a deficit, in millions of national currency: a negative value is a deficit (spending exceeding revenue) and a positive value is a surplus.
Also known as: budget deficit, fiscal deficit.
Government Deficit in Python
get_government_deficit is part of the Economics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_government_deficit as shown below.
from financetoolkit import Economics
economics = Economics(start_date='2015-01-01')
economics.get_government_deficit(countries=['United States', 'Canada', 'Mexico'])
Which returns:
| United States | Canada | Mexico | |
|---|---|---|---|
| 2015 | -645814 | -1234.07 | -742032 |
| 2016 | -819141 | -9175.67 | -556543 |
| 2017 | -940204 | -2397.52 | -233024 |
| 2018 | -1.10203e+06 | 8048.43 | -517139 |
| 2019 | -1.24932e+06 | -393.306 | -569235 |
| 2020 | -2.97292e+06 | -243126 | -1.03335e+06 |
| 2021 | -2.61038e+06 | -73474.8 | -1.00008e+06 |
| 2022 | -1.02051e+06 | 3066.48 | -1.25793e+06 |
| 2023 | -1.9593e+06 | -16572 | -1.36948e+06 |
| 2024 | -2.22521e+06 | -59827.1 | -2.01778e+06 |
| 2025 | -2.22159e+06 | -32373.6 | -1.28252e+06 |
Parameters
get_government_deficit accepts the following parameters:
- countries (list[str] | str | None, optional): A list of countries or a single country to include in the results. Defaults to None.
- rolling (int, optional): The rolling window size to use for smoothing the data (simple moving average). Defaults to None.
- trailing (int, optional): The trailing window size to use for summing the data over trailing periods (e.g. a trailing-4-quarter sum). Defaults to None.
- growth (bool, optional): Whether to return the growth data or the actual data. Defaults to False.
- lag (int, optional): The number of periods to lag the growth data. Defaults to 1.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.