Foreign direct investment, net outflows (BoP, current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 33,063,215 -0.878% 76
Albania Albania 260,598,127 -0.829% 57
Argentina Argentina 2,689,756,979 -9.17% 37
Armenia Armenia 63,049,240 +17.1% 72
Antigua & Barbuda Antigua & Barbuda 17,875,414 -2.88% 78
Australia Australia 15,670,153,591 +15.2% 19
Austria Austria 10,808,352,963 +29.1% 24
Azerbaijan Azerbaijan 742,439,000 -60.4% 48
Belgium Belgium -6,071,749,809 -54.5% 100
Bangladesh Bangladesh -2,066,943 +0.209% 89
Bulgaria Bulgaria 1,034,050,000 -18.9% 44
Bahrain Bahrain 275,000,000 -75.3% 56
Bahamas Bahamas 162,940,696 -27.7% 62
Bosnia & Herzegovina Bosnia & Herzegovina 78,871,697 -21.8% 68
Belarus Belarus 147,808,300 +128% 64
Belize Belize 2,611,033 +15.8% 82
Brazil Brazil 24,318,633,535 -3.3% 16
Canada Canada 84,318,213,649 -5.03% 4
Switzerland Switzerland -34,741,952,844 -264% 101
Chile Chile 3,591,884,332 -59% 34
China China 172,243,715,124 -23.7% 3
Colombia Colombia 4,611,273,533 +263% 33
Cape Verde Cape Verde 20,462,405 +174% 77
Costa Rica Costa Rica 1,002,321,490 +1.57% 45
Czechia Czechia 11,178,591,687 +32.3% 23
Germany Germany 80,163,888,039 -22.4% 5
Dominica Dominica 419,176 +4.48% 87
Denmark Denmark 31,197,577,666 +188% 14
Dominican Republic Dominican Republic -47,300,000 -113% 94
Spain Spain 52,467,056,374 +32.2% 9
Estonia Estonia -3,709,258,287 -268% 99
Finland Finland 5,567,095,891 -620% 32
France France 46,960,819,424 +19.4% 11
United Kingdom United Kingdom 68,306,255,487 +126% 7
Georgia Georgia 461,813,110 -2.27% 51
Greece Greece 1,793,187,316 -55.7% 39
Grenada Grenada 2,719,816 -250% 81
Guatemala Guatemala 825,128,010 +26.1% 47
Hong Kong SAR China Hong Kong SAR China 78,101,368,252 -18.8% 6
Honduras Honduras 688,933,876 +200% 49
Croatia Croatia 2,787,562,288 +104% 36
Hungary Hungary -48,370,788,028 -33.8% 102
Indonesia Indonesia 9,278,205,589 +30.2% 27
India India 23,768,827,657 +71.3% 17
Iceland Iceland 454,454,917 +34.3% 52
Israel Israel 10,477,700,000 +32.4% 25
Italy Italy 34,074,475,461 +11.4% 13
Jamaica Jamaica 1,068,505 -127% 86
Japan Japan 208,220,716,289 +6.54% 2
Kazakhstan Kazakhstan -1,891,328,644 -162% 97
Cambodia Cambodia 171,829,024 +13.5% 60
St. Kitts & Nevis St. Kitts & Nevis 2,399,445 -347% 83
South Korea South Korea 48,588,800,000 +51% 10
Kuwait Kuwait 10,323,275,043 -7.84% 26
St. Lucia St. Lucia -8,143,562 -72.9% 91
Lithuania Lithuania 156,155,557 -93.5% 63
Latvia Latvia 222,365,011 -78.2% 58
Moldova Moldova 89,550,000 +474% 66
Mexico Mexico 12,720,718,201 +1,585% 22
North Macedonia North Macedonia -2,988,430 -103% 90
Malta Malta 30,908,805,367 +28.4% 15
Montenegro Montenegro 67,797,270 +18.3% 70
Mozambique Mozambique -44,109,636 -125% 93
Malaysia Malaysia 13,038,524,470 +63.7% 20
Namibia Namibia 40,911,854 -113% 74
Nigeria Nigeria 407,953,708 +59.5% 53
Nicaragua Nicaragua 73,800,000 +75.3% 69
Netherlands Netherlands 12,792,985,864 -104% 21
Norway Norway -2,966,706,726 -129% 98
New Zealand New Zealand 1,510,131,052 -752% 41
Pakistan Pakistan 84,000,000 +163% 67
Panama Panama 864,528,503 -13.6% 46
Philippines Philippines 2,871,633,477 -18.5% 35
Poland Poland 7,764,000,000 -47.5% 29
Portugal Portugal 6,710,415,402 +19% 30
Paraguay Paraguay 64,806,131 -74.3% 71
Palestinian Territories Palestinian Territories 10,688,879 +238% 79
Qatar Qatar 1,562,912,088 -916% 40
Romania Romania 1,145,797,067 -37.3% 43
Russia Russia 168,770,000 -98.4% 61
Saudi Arabia Saudi Arabia 22,045,700,408 +27.1% 18
Singapore Singapore 55,257,415,122 +41.9% 8
Solomon Islands Solomon Islands 52,877,561 +723% 73
El Salvador El Salvador 287,808,789 -739% 55
Suriname Suriname -11,050,199 -206% 92
Slovakia Slovakia 2,308,600,310 -655% 38
Slovenia Slovenia 1,400,320,218 +68.9% 42
Sweden Sweden 35,647,554,285 -11.8% 12
Thailand Thailand 7,800,987,844 -43% 28
Tajikistan Tajikistan 101,024,554 +152% 65
Timor-Leste Timor-Leste 4,500,000 -107% 80
Tonga Tonga 1,253,493 +9.83% 85
Trinidad & Tobago Trinidad & Tobago 214,766,719 -59.5% 59
Turkey Turkey 6,596,000,000 +10.6% 31
Ukraine Ukraine 305,000,000 +136% 54
Uruguay Uruguay -162,769,084 -98% 95
United States United States 379,072,000,000 -16.5% 1
Uzbekistan Uzbekistan 36,693,522 +213% 75
St. Vincent & Grenadines St. Vincent & Grenadines -277,307 -22.7% 88
Vietnam Vietnam 600,000,000 -139% 50
Samoa Samoa 2,049,882 -480,274% 84
South Africa South Africa -1,331,067,898 -52.7% 96

                    
# 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 = 'BM.KLT.DINV.CD.WD'

# 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 <- 'BM.KLT.DINV.CD.WD'

# 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))