Military expenditure (% of GDP)

Source: worldbank.org, 01.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Angola Angola 1.33 +1.19% 88
Albania Albania 1.74 +44% 61
Argentina Argentina 0.473 -31.1% 141
Armenia Armenia 5.45 +33.5% 7
Australia Australia 1.92 +0.726% 56
Austria Austria 0.844 +9.86% 118
Azerbaijan Azerbaijan 4.6 +21.1% 12
Burundi Burundi 3.66 +40.8% 18
Belgium Belgium 1.21 +2.72% 100
Benin Benin 0.711 +12.5% 126
Burkina Faso Burkina Faso 4.01 +34.5% 14
Bangladesh Bangladesh 1.02 -2.77% 109
Bulgaria Bulgaria 1.85 +16% 57
Bahrain Bahrain 3.11 -1.18% 23
Bosnia & Herzegovina Bosnia & Herzegovina 0.808 +19% 120
Belarus Belarus 1.8 +9.04% 59
Belize Belize 0.822 +1.43% 119
Bolivia Bolivia 1.39 +42.4% 86
Brazil Brazil 1.08 +0.834% 107
Brunei Brunei 2.97 +13.7% 24
Botswana Botswana 2.53 +6.2% 35
Central African Republic Central African Republic 2.29 +33.8% 41
Canada Canada 1.29 +8.13% 91
Switzerland Switzerland 0.703 +1.77% 127
Chile Chile 1.63 +5.46% 69
China China 1.67 +2.6% 66
Côte d’Ivoire Côte d’Ivoire 0.886 -0.309% 115
Cameroon Cameroon 0.933 -0.973% 111
Congo - Kinshasa Congo - Kinshasa 1.16 +101% 103
Congo - Brazzaville Congo - Brazzaville 2 +4.85% 52
Colombia Colombia 2.87 +2.17% 26
Cape Verde Cape Verde 0.528 +15.5% 138
Cyprus Cyprus 1.82 +0.103% 58
Czechia Czechia 1.52 +10.6% 78
Germany Germany 1.52 +10.3% 79
Denmark Denmark 1.95 +42.8% 55
Dominican Republic Dominican Republic 0.741 +10.9% 124
Algeria Algeria 8.17 +74.1% 3
Ecuador Ecuador 2.3 +2.18% 40
Egypt Egypt 0.871 -17% 117
Spain Spain 1.51 +5.23% 81
Estonia Estonia 2.87 +32.7% 27
Ethiopia Ethiopia 0.788 -9.37% 122
Finland Finland 2.42 +53.9% 37
Fiji Fiji 1.32 -2.43% 89
France France 2.06 +6.41% 50
Gabon Gabon 1.15 -12.5% 104
United Kingdom United Kingdom 2.26 +9.21% 43
Georgia Georgia 1.68 +14.7% 65
Ghana Ghana 0.389 +15.2% 143
Guinea Guinea 2.13 -1.97% 45
Gambia Gambia 0.584 -15.8% 133
Guinea-Bissau Guinea-Bissau 1.46 -10.3% 85
Equatorial Guinea Equatorial Guinea 1.59 +22% 73
Greece Greece 3.23 -19.6% 22
Guatemala Guatemala 0.411 -11.5% 142
Guyana Guyana 0.587 -2.47% 132
Honduras Honduras 1.57 +7.85% 75
Croatia Croatia 1.78 -0.722% 60
Haiti Haiti 0.0541 -21.3% 148
Hungary Hungary 2.13 +15.9% 44
Indonesia Indonesia 0.678 -11.8% 128
India India 2.44 +3.35% 36
Ireland Ireland 0.217 -0.821% 146
Iran Iran 2.06 -2.37% 49
Iraq Iraq 2.07 +14.8% 47
Israel Israel 5.32 +19.3% 9
Italy Italy 1.61 -5.24% 72
Jamaica Jamaica 1.22 -5.09% 97
Jordan Jordan 4.91 +0.186% 10
Japan Japan 1.2 +8.15% 101
Kazakhstan Kazakhstan 0.48 -7.22% 140
Kenya Kenya 0.906 -10.3% 114
Kyrgyzstan Kyrgyzstan 3.62 +18.6% 20
Cambodia Cambodia 2.09 -0.0181% 46
South Korea South Korea 2.81 +1.54% 29
Kuwait Kuwait 4.9 +3.55% 11
Lebanon Lebanon 8.91 +205% 2
Liberia Liberia 2.3 -7.64% 39
Sri Lanka Sri Lanka 1.64 +22.1% 67
Lesotho Lesotho 1.54 +1.31% 76
Lithuania Lithuania 2.72 +11% 32
Luxembourg Luxembourg 0.749 +19.8% 123
Latvia Latvia 2.27 +8.28% 42
Morocco Morocco 3.64 -4.61% 19
Moldova Moldova 0.547 +66.2% 136
Madagascar Madagascar 0.663 -0.444% 129
Mexico Mexico 0.657 -4.25% 130
North Macedonia North Macedonia 1.7 +4.68% 64
Mali Mali 3.83 +21.9% 16
Malta Malta 0.559 +29.2% 135
Myanmar (Burma) Myanmar (Burma) 3.79 -7.27% 17
Montenegro Montenegro 1.63 +1.67% 68
Mongolia Mongolia 0.601 +17% 131
Mozambique Mozambique 1.73 +15.5% 62
Mauritania Mauritania 2.55 +11.8% 34
Mauritius Mauritius 0.153 +10.1% 147
Malawi Malawi 1.01 +4.25% 110
Malaysia Malaysia 0.93 +3.06% 112
Namibia Namibia 2.74 -6.09% 31
Niger Niger 2.07 +24.4% 48
Nigeria Nigeria 0.807 +24.2% 121
Nicaragua Nicaragua 0.546 +1.65% 137
Netherlands Netherlands 1.53 +13.3% 77
Norway Norway 1.61 +7.11% 71
Nepal Nepal 1.08 -3.02% 108
New Zealand New Zealand 1.22 +3.91% 99
Oman Oman 5.4 +7.15% 8
Pakistan Pakistan 2.8 -11.4% 30
Peru Peru 1.12 -2.77% 106
Philippines Philippines 1.25 -5.09% 96
Papua New Guinea Papua New Guinea 0.313 +0.198% 144
Poland Poland 3.83 +72% 15
Portugal Portugal 1.52 +8.58% 80
Paraguay Paraguay 0.906 +8.99% 113
Romania Romania 1.61 -6.43% 70
Russia Russia 5.86 +25% 6
Rwanda Rwanda 1.27 -5.08% 93
Saudi Arabia Saudi Arabia 7.09 +10.8% 4
Senegal Senegal 1.47 -4.57% 84
Singapore Singapore 2.66 +3.14% 33
Sierra Leone Sierra Leone 0.56 -18.3% 134
El Salvador El Salvador 1.28 -9.03% 92
Serbia Serbia 2.85 +5.23% 28
South Sudan South Sudan 6.26 +50.7% 5
Slovakia Slovakia 2.02 +11.5% 51
Slovenia Slovenia 1.34 +3.45% 87
Sweden Sweden 1.47 +12.8% 83
Eswatini Eswatini 1.57 -4.67% 74
Seychelles Seychelles 1.71 +28.1% 63
Chad Chad 2.91 +5.83% 25
Togo Togo 4.01 -26.2% 13
Thailand Thailand 1.17 -6.34% 102
Tajikistan Tajikistan 1.22 -38.9% 98
Timor-Leste Timor-Leste 1.26 +14% 94
Trinidad & Tobago Trinidad & Tobago 0.886 +19.4% 116
Tunisia Tunisia 2.36 -4.67% 38
Turkey Turkey 1.5 +26.4% 82
Tanzania Tanzania 1.15 +1.3% 105
Uganda Uganda 1.98 -2.69% 54
Ukraine Ukraine 36.7 +41.6% 1
Uruguay Uruguay 2 +9.58% 53
United States United States 3.36 +0.556% 21
Venezuela Venezuela 0.501 -23% 139
Kosovo Kosovo 1.25 +9.55% 95
South Africa South Africa 0.733 -4.52% 125
Zambia Zambia 1.3 +16.5% 90
Zimbabwe Zimbabwe 0.249 -68.1% 145

The indicator 'Military expenditure (% of GDP)' measures the proportion of a country’s gross domestic product (GDP) that is allocated to military spending. This percentage gives insight into a nation’s prioritization of defense and military expenditures relative to its overall economic output. The significance of this indicator lies not only in its representation of a country’s military capabilities but also in how it reflects public policy decisions, geopolitical stability, and potential threats faced by a nation.

Military expenditure, as a percentage of GDP, serves several important roles. First, it provides a comparative framework to assess military spending across different countries. By examining this data, analysts can identify trends in military investment that indicate a country’s strategic intentions and readiness. For example, countries experiencing conflict or heightened tensions often increase their military budgets, which can be observed in the case of Ukraine, with military expenditure reaching an exceptional rate of 33.55% of GDP in 2022. This stark contrast to the median value of 1.46% highlights the extreme circumstances that necessitate such financial commitment towards military funding.

The relation of military expenditure to other indicators is multifaceted. A high military expenditure percentage can correlate to geopolitical tensions, defense contracts, and a nation's economic health. For instance, strong economies with stable political environments might allocate a smaller percentage of their GDP to military investments, instead focusing on social programs or infrastructure. In contrast, nations like Saudi Arabia (7.42%) and Qatar (6.96%), while having relatively strong economies due to oil revenue, showcase a significant focus on military spending, likely influenced by regional conflicts and security challenges. This connects directly to the notion of the “security-dilemma,” where one nation's military build-up may prompt neighboring nations to increase their military spending in response.

Various factors can impact the military expenditure as a percentage of GDP. These include political scenarios, historical contexts, economic conditions, and the global security environment. Economic downturns may compel governments to adjust defense budgets, often leading to decreased military spending. Additionally, international treaties and obligations, such as NATO commitments, can dictate the levels of spending a country must maintain. On the other hand, geopolitical threats or ongoing military engagements can lead to increased spending. The data indicates a general trend where military expenditure relative to GDP tended to decline from the 1960s (averaging over 6%) steadily down to around 2.28% in 2022, possibly reflecting the end of the Cold War era and shifting global priorities.

Strategies for managing military expenditure often focus on balancing national security with economic constraints. Countries may seek to optimize defense spending by adopting technology that enhances efficiency or reduces costs. Joint military exercises and shared resources among allied nations can also alleviate budget burdens. Additionally, transparency in military spending can help reduce corruption and promote efficient use of resources. Nevertheless, states need to ensure that their military capacities are sufficient to protect their sovereignty and interests, illustrating the need for an intricate balance.

In addressing flaws in military expenditure assessments, it is crucial to consider the potential inadequacies of the GDP metric itself. GDP does not accurately capture the informal economy or living standards, which can skew the military expenditure percentage. Additionally, the focus on expenditure alone can misrepresent the actual military effectiveness if that spending does not translate into operational success or military readiness.

The latest data from 2022 gives us a clearer picture of these dynamics. The median military expenditure across countries stands at 1.46%, a reflection of a general trend towards reduced military spending among many nations. However, specific countries exhibit extreme deviations from this median. While Ukraine's military expenditure is largely a response to the ongoing conflict and geopolitical instability, nations such as Saudi Arabia and Qatar maintain high spending partly due to oil wealth and regional security dynamics. Conversely, on the lower end of the spectrum, countries like Haiti (0.07%) and Mauritius (0.17%) allocate minimal resources to military expenditures, often reflecting different priorities in governance and security challenges.

Overall, military expenditure (% of GDP) serves as a critical indicator in assessing a country’s military priorities and potential. Understanding its context requires analyzing geopolitical dynamics, economic factors, and the interplay of global security trends. The disparities in military spending among countries point to varying security needs and economic strategies, making this indicator a vital tool for policymakers, analysts, and scholars alike in assessing national defense strategies and international relations.

                    
# Install missing packages
import sys
import subprocess

def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])

# Required packages
for package in ['wbdata', 'country_converter']:
try:
__import__(package)
except ImportError:
install(package)

# Import libraries
import wbdata
import country_converter as coco
from datetime import datetime

# Define World Bank indicator code
dataset_code = 'MS.MIL.XPND.GD.ZS'

# Download data from World Bank API
data = wbdata.get_dataframe({dataset_code: 'value'},
date=(datetime(1960, 1, 1), datetime.today()),
parse_dates=True,
keep_levels=True).reset_index()

# Extract year
data['year'] = data['date'].dt.year

# Convert country names to ISO codes using country_converter
cc = coco.CountryConverter()
data['iso2c'] = cc.convert(names=data['country'], to='ISO2', not_found=None)
data['iso3c'] = cc.convert(names=data['country'], to='ISO3', not_found=None)

# Filter out rows where ISO codes could not be matched — likely not real countries
data = data[data['iso2c'].notna() & data['iso3c'].notna()]

# Sort for calculation
data = data.sort_values(['iso3c', 'year'])

# Calculate YoY absolute and percent change
data['value_change'] = data.groupby('iso3c')['value'].diff()
data['value_change_percent'] = data.groupby('iso3c')['value'].pct_change() * 100

# Calculate ranks (higher GDP per capita = better rank)
data['rank'] = data.groupby('year')['value'].rank(ascending=False, method='dense')

# Calculate rank change from previous year
data['rank_change'] = data.groupby('iso3c')['rank'].diff()

# Select desired columns
final_df = data[['country', 'iso2c', 'iso3c', 'year', 'value',
'value_change', 'value_change_percent', 'rank', 'rank_change']].copy()

# Optional: Add labels as metadata (could be useful for export or UI)
column_labels = {
'country': 'Country name',
'iso2c': 'ISO 2-letter country code',
'iso3c': 'ISO 3-letter country code',
'year': 'Year',
'value': 'GDP per capita (current US$)',
'value_change': 'Year-over-Year change in value',
'value_change_percent': 'Year-over-Year percent change in value',
'rank': 'Country rank by GDP per capita (higher = richer)',
'rank_change': 'Change in rank from previous year'
}

# Display first few rows
print(final_df.head(10))

# Optional: Save to CSV
#final_df.to_csv("gdp_per_capita_cleaned.csv", index=False)
                    
                
                    
# Check and install required packages
required_packages <- c("WDI", "countrycode", "dplyr")

for (pkg in required_packages) {
  if (!requireNamespace(pkg, quietly = TRUE)) {
    install.packages(pkg)
  }
}

# Load the necessary libraries
library(WDI)
library(dplyr)
library(countrycode)

# Define the dataset code (World Bank indicator code)
dataset_code <- 'MS.MIL.XPND.GD.ZS'

# Download data using WDI package
dat <- WDI(indicator = dataset_code)

# Filter only countries using 'is_country' from countrycode
# This uses iso2c to identify whether the entry is a recognized country
dat <- dat %>%
  filter(countrycode(iso2c, origin = 'iso2c', destination = 'country.name', warn = FALSE) %in%
           countrycode::codelist$country.name.en)

# Ensure dataset is ordered by country and year
dat <- dat %>%
  arrange(iso3c, year)

# Rename the dataset_code column to "value" for easier manipulation
dat <- dat %>%
  rename(value = !!dataset_code)

# Calculate year-over-year (YoY) change and percentage change
dat <- dat %>%
  group_by(iso3c) %>%
  mutate(
    value_change = value - lag(value),                              # Absolute change from previous year
    value_change_percent = 100 * (value - lag(value)) / lag(value) # Percent change from previous year
  ) %>%
  ungroup()

# Calculate rank by year (higher value => higher rank)
dat <- dat %>%
  group_by(year) %>%
  mutate(rank = dense_rank(desc(value))) %>% # Rank countries by descending value
  ungroup()

# Calculate rank change (positive = moved up, negative = moved down)
dat <- dat %>%
  group_by(iso3c) %>%
  mutate(rank_change = rank - lag(rank)) %>% # Change in rank compared to previous year
  ungroup()

# Select and reorder final columns
final_data <- dat %>%
  select(
    country,
    iso2c,
    iso3c,
    year,
    value,
    value_change,
    value_change_percent,
    rank,
    rank_change
  )

# Add labels (variable descriptions)
attr(final_data$country, "label") <- "Country name"
attr(final_data$iso2c, "label") <- "ISO 2-letter country code"
attr(final_data$iso3c, "label") <- "ISO 3-letter country code"
attr(final_data$year, "label") <- "Year"
attr(final_data$value, "label") <- "GDP per capita (current US$)"
attr(final_data$value_change, "label") <- "Year-over-Year change in value"
attr(final_data$value_change_percent, "label") <- "Year-over-Year percent change in value"
attr(final_data$rank, "label") <- "Country rank by GDP per capita (higher = richer)"
attr(final_data$rank_change, "label") <- "Change in rank from previous year"

# Print the first few rows of the final dataset
print(head(final_data, 10))