Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-rivera committed Jan 19, 2024
1 parent 472a992 commit bfda8b9
Show file tree
Hide file tree
Showing 21 changed files with 1,727 additions and 27 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Project title
Project description
# Net Flows Research

_Note: this project is still in progress. Data, methodology and outputs may change without warning._

This repository contains the code and data for ONE's research on the net flows (concessional and non-concessional)
received by developing countries.
1,304 changes: 1,304 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "scripts"
version = "1"
description = "Tools to assess the net flows to developing countries"
authors = ["Jorge Rivera <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
bblocks = "^1.2.1"
pandas = "^2.1.4"
numpy = "^1.26.3"
pyarrow = "^14.0.2"
oda-data = "^1.0.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added raw_data/table2a_raw.feather
Binary file not shown.
3 changes: 3 additions & 0 deletions scripts/CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 2024-01-18
The repository was first created with the basic structure,
dependency management, description, etc.
28 changes: 28 additions & 0 deletions scripts/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from pathlib import Path


Expand All @@ -8,3 +9,30 @@ class Paths:
raw_data = project / "raw_data"
output = project / "output"
scripts = project / "scripts"


CONSTANT_BASE_YEAR: int = 2022
PRICES_SOURCE: str = "imf"
ANALYSIS_YEARS: tuple = (2010, 2022)

# Create a root logger
logger = logging.getLogger(__name__)

# Create the terminal handler
shell_handler = logging.StreamHandler()

# Set levels for the logger, shell and file
logger.setLevel(logging.DEBUG)
shell_handler.setLevel(logging.DEBUG)

# Format the outputs
fmt_shell = "%(levelname)s %(message)s"

# Create formatters
shell_formatter = logging.Formatter(fmt_shell)

# Add formatters to handlers
shell_handler.setFormatter(shell_formatter)

# Add handlers to the logger
logger.addHandler(shell_handler)
9 changes: 9 additions & 0 deletions scripts/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Data
This module contains scripts to get and process the data used in the analysis.

## inflows.py
This script downloads and processes the data debt inflows from the
World Bank's [International Debt Statistics](https://datacatalog.worldbank.org/dataset/international-debt-statistics)
database.

The data is saved in the `raw_data` folder. The processed data is saved in the `output` folder.
File renamed without changes.
180 changes: 180 additions & 0 deletions scripts/data/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import logging

import pandas as pd
from bblocks import convert_id

logging.getLogger("country_converter").setLevel(logging.ERROR)

def multilateral_mapping() -> dict:
return {
"African Dev. Bank": "African Development Bank",
"African Export-Import Bank": "African Export Import Bank",
"Arab African International Bank": "Arab African International Bank",
"Arab Bank for Economic Dev. in Africa (BADEA)": (
"Arab Bank for Economic Development in Africa"
),
"Arab Fund for Tech. Assist. to African Countries": (
"Arab Fund for Technical Assistance to African Countries"
),
"Arab International Bank": "Arab International Bank",
"Arab League": "Arab League",
"Arab Monetary Fund": "Arab Monetary Fund",
"Arab Towns Organization (ATO)": "Arab Towns Organization",
"Asian Dev. Bank": "Asian Development Bank",
"Asian Infrastructure Investment Bank": "Asian Infrastructure Investment Bank",
"Bank for International Settlements (BIS)": "Bank for International Settlements",
"Bolivarian Alliance for the Americas (ALBA)": (
"Bolivarian Alliance for the Americas"
),
"Caribbean Community (CARICOM)": "Caribbean Community",
"Caribbean Dev. Bank": "Caribbean Development Bank",
"Center for Latin American Monetary Studies (CEMLA)": (
"Center for Latin American Monetary Studies"
),
"Central American Bank for Econ. Integ. (CABEI)": (
"Central American Bank for Economic Integration"
),
"Central American Bank for Econ. Integration (BCIE)": (
"Central American Bank for Economic Integration"
),
"Central Bank of West African States (BCEAO)": (
"Central Bank of West African States"
),
"Corporacion Andina de Fomento": "Corporacion Andina de Fomento",
"Council of Europe": "Council of Europe",
"Dev. Bank of the Central African States (BDEAC)": (
"Development Bank of the Central African States"
),
"East African Community": "East African Community",
"Eastern & Southern African Trade & Dev. Bank (TDB)": (
"Eastern and Southern African Trade and Development Bank"
),
"ECO Trade and Dev. Bank": "ECO Trade and Development Bank",
"Econ. Comm. of the Great Lakes Countries (ECGLC)": (
"Economic Community of the Great Lakes Countries"
),
"Economic Community of West African States (ECOWAS)": (
"Economic Community of West African States"
),
"Eurasian Development Bank": "Eurasian Development Bank",
"EUROFIMA": "EUROFIMA",
"European Bank for Reconstruction and Dev. (EBRD)": (
"European Bank for Reconstruction and Development"
),
"European Coal and Steel Community (ECSC)": (
"European Coal and Steel Community"
),
"European Development Fund (EDF)": "European Development Fund",
"European Economic Community (EEC)": "European Economic Community",
"European Free Trade Association (EFTA)": "European Free Trade Association",
"European Investment Bank": "European Investment Bank",
"European Relief Fund": "European Relief Fund",
"European Social Fund (ESF)": "European Social Fund",
"European Union": "European Union",
"Fondo Latinoamericano de Reservas (FLAR)": "Fondo Latinoamericano de Reservas",
"Food and Agriculture Organization (FAO)": "Food and Agriculture Organization",
"Foreign Trade Bank of Latin America (BLADEX)": (
"Foreign Trade Bank of Latin America"
),
"Global Environment Facility": "Global Environment Facility",
"Inter-American Dev. Bank": "Inter-American Development Bank",
"International Bank for Economic Cooperation (IBEC)": (
"International Bank for Economic Cooperation"
),
"International Coffee Organization (ICO)": "International Coffee Organization",
"International Finance Corporation": "International Finance Corporation",
"International Fund for Agricultural Dev.": (
"International Fund for Agricultural Development"
),
"International Investment Bank (IIB)": "International Investment Bank",
"International Labour Organization (ILO)": "International Labour Organization",
"International Monetary Fund": "International Monetary Fund",
"Islamic Dev. Bank": "Islamic Development Bank",
"Islamic Solidarity Fund for Dev. (ISFD)": "Islamic Solidarity Fund for Development",
"Latin Amer. Conf. of Saving & Credit Coop. (COLAC)": (
"Latin American Conference of Saving and Credit Cooperation"
),
"Latin American Agribusiness Dev. Corp. (LAAD)": (
"Latin American Agribusiness Development Corporation"
),
"Montreal Protocol Fund": "Montreal Protocol Fund",
"Nordic Development Fund": "Nordic Development Fund",
"Nordic Environment Finance Corporation (NEFCO)": "Nordic Environment Finance Corporation",
"Nordic Investment Bank": "Nordic Investment Bank",
"OPEC Fund for International Dev.": "OPEC Fund for International Development",
"Org. of Arab Petroleum Exporting Countries (OAPEC)": (
"Organization of Arab Petroleum Exporting Countries"
),
"Plata Basin Financial Dev. Fund": "Plata Basin Financial Development Fund",
"South Asian Development Fund (SADF)": "South Asian Development Fund",
"UN-Children's Fund (UNICEF)": "UNICEF",
"UN-Development Fund for Women (UNIFEM)": "UN Development Fund for Women",
"UN-Development Programme (UNDP)": "UN Development Programme",
"UN-Educ., Scientific and Cultural Org. (UNESCO)": "UNESCO",
"UN-Environment Programme (UNEP)": "UN Environment Programme",
"UN-Fund for Drug Abuse Control (UNFDAC)": "UN Fund for Drug Abuse Control",
"UN-Fund for Human Rights": "UN Fund for Human Rights",
"UN-General Assembly (UNGA)": "UN General Assembly",
"UN-High Commissioner for Refugees (UNHCR)": "UN High Commissioner for Refugees",
"UN-Industrial Development Organization (UNIDO)": (
"UN Industrial Development Organization"
),
"UN-INSTRAW": (
"UN International Research and Training Institute for the Advancement of Women"
),
"UN-Office on Drugs and Crime (UNDCP)": "UN Office on Drugs and Crime",
"UN-Population Fund (UNFPA)": "UN Population Fund",
"UN-Regular Programme of Technical Assistance": (
"UN Regular Programme of Technical Assistance"
),
"UN-Regular Programme of Technical Coop. (RPTC)": (
"UN Regular Programme of Technical Assistance"
),
"UN-Relief and Works Agency (UNRWA)": "UN Relief and Works Agency",
"UN-UNETPSA": "UN UNETPSA",
"UN-World Food Programme (WFP)": "UN World Food Programme",
"UN-World Intellectual Property Organization": "UN World Intellectual Property Organization",
"UN-World Meteorological Organization": "UN World Meteorological Organization",
"West African Development Bank - BOAD": "West African Development Bank",
"West African Monetary Union (UMOA)": "West African Monetary Union",
"World Bank-IBRD": "WB International Bank for Reconstruction and Development",
"World Bank-IDA": "WB International Development Association",
"World Bank-MIGA": "WB Multilateral Investment Guarantee Agency",
"World Trade Organization": "World Trade Organization",
}


def clean_debtors(df: pd.DataFrame, column) -> pd.DataFrame:
df["iso_code"] = convert_id(df[column], from_type="regex", to_type="ISO3")
df["continent"] = convert_id(df[column], from_type="regex", to_type="continent")
df[column] = convert_id(df[column], from_type="regex", to_type="name_short")

return df.set_index(["iso_code", column, "continent"]).reset_index()


def clean_creditors(df: pd.DataFrame, column) -> pd.DataFrame:
additional_iso = {
"Korea, D.P.R. of": "PRK",
"German Dem. Rep.": "DEU",
"Neth. Antilles": "ANT",
"Yugoslavia": "YUG",
}
additional_names = {
"Korea, D.P.R. of": "North Korea",
"German Dem. Rep.": "Germany",
"Neth. Antilles": "Netherlands Antilles",
}
df["counterpart_iso_code"] = convert_id(
df[column],
from_type="regex",
to_type="ISO3",
additional_mapping=multilateral_mapping() | additional_iso,
)
df[column] = convert_id(
df[column],
from_type="regex",
to_type="name_short",
additional_mapping=multilateral_mapping() | additional_names,
)

return df
Loading

0 comments on commit bfda8b9

Please sign in to comment.