International Debt Analysis - Exploring PostgreSQL

L

Loi2008

Guest

1. Introduction​


This analysis explores a sample international debt dataset using PostgreSQL. The goal is to understand the structure of the data, assess data quality, and generate insights about global debt distribution. The dataset contains information on countries, debt indicators, and debt value. It also includes missing values that must be handled carefully during analysis, if accurate meaning is to be drawn from the dataset.

2. Loading the Dataset​


**Assuming there is an active connected postgresql.

Steps:​

  • Open PostgreSQL in Dbeaver
  • Create a schema

Code:
create schema international_debt_analysis);

Set the search path


Code:
set search_path to international_debt_analysis);
  • Right click on tables under your schema

  • Import data


  • Select the source file


  • Map the table to the schema


  • Confirm


  • Proceed


  • Open a new script


  • Confirm your table is in the right schema

Code:
select * from international_debt_with_missing_values;

3. SQL Queries and Findings​


The data is analysed using SQL queries. Charts and tables are used for visualization.

3.1 The Total Amount of Debt Owed​


Code:
select sum(debt) as total_debt 
from international_debt_with_missing_values;

se Total Debt** = 2,823,894,600,000**

3.2 Number of Distinct Countries​


Code:
select count(distinct country_name) as distinct_country 
from international_debt_with_missing_values;

Distinct Countries = 125

3.3 Distinct Types of Debt Indicators​


Code:
select distinct indicator_code, indicator_name
from international_debt_with_missing_values
where indicator_name is not null
and indicator_name <> ''
and indicator_code is not null
and indicator_code <> '';

Table1: Distinct Debt Indicators​

Indicator CodeIndicator Description
DT.INT.PRVT.CDPPG, private creditors (INT, current US$)
DT.AMT.OFFT.CDPPG, official creditors (AMT, current US$)
DT.INT.DLXF.CDInterest payments on external debt, long-term (INT, current US$)
DT.INT.DPNG.CDInterest payments on external debt, private nonguaranteed (PNG) (INT, current US$)
DT.DIS.PCBK.CDPPG, commercial banks (DIS, current US$)
DT.AMT.PBND.CDPPG, bonds (AMT, current US$)
DT.DIS.MLAT.CDPPG, multilateral (DIS, current US$)
DT.DIS.PRVT.CDPPG, private creditors (DIS, current US$)
DT.INT.MLAT.CDPPG, multilateral (INT, current US$)
DT.INT.PBND.CDPPG, bonds (INT, current US$)
DT.INT.PROP.CDPPG, other private creditors (INT, current US$)
DT.DIS.OFFT.CDPPG, official creditors (DIS, current US$)
DT.AMT.MLAT.CDPPG, multilateral (AMT, current US$)
DT.INT.OFFT.CDPPG, official creditors (INT, current US$)
DT.DIS.PROP.CDPPG, other private creditors (DIS, current US$)
DT.AMT.PCBK.CDPPG, commercial banks (AMT, current US$)
DT.DIS.BLAT.CDPPG, bilateral (DIS, current US$)
DT.AMT.DLXF.CDPrincipal repayments on external debt, long-term (AMT, current US$)
DT.AMT.PROP.CDPPG, other private creditors (AMT, current US$)
DT.AMT.PRVT.CDPPG, private creditors (AMT, current US$)
DT.AMT.BLAT.CDPPG, bilateral (AMT, current US$)
DT.INT.PCBK.CDPPG, commercial banks (INT, current US$)
DT.INT.BLAT.CDPPG, bilateral (INT, current US$)
DT.DIS.DLXF.CDDisbursements on external debt, long-term (DIS, current US$)
DT.AMT.DPNG.CDPrincipal repayments on external debt, private nonguaranteed (PNG) (AMT, current US$)

3.4 Country with Highest Total Debt, and the Amount​


Code:
select country_name, sum(debt) as total_debt
from international_debt_with_missing_values
where country_name is not null
and country_name <> ''
group by country_name
order by total_debt desc
limit 1;

The county is China with the debt of 266,455,760,000

3.5 The Average Debt Across Different Debt Indicators​


Code:
select indicator_name, AVG(debt) AS avg_debt
from international_debt_with_missing_values
group by indicator_name
order by avg_debt desc;

Average debt categorized by debt indicators

Fig1: Average Debt per Indicator Category​

3.6 Country with Highest Principal Repayment​


Code:
select country_name, SUM(debt) AS total_principal_repayment
from international_debt_with_missing_values
where indicator_name like '%Principal repayment%' and debt> 0
group by country_name
order by total_principal_repayment desc
limit 1;

The county is China with the principal repayment amount of 168,611,610,000

3.7 Most Common Debt Indicator​


Code:
select indicator_name, count(*) as frequency
from international_debt_with_missing_values
where indicator_name is not null
and indicator_name <> ''
group by indicator_name
order by frequency desc;
limit 1;

the most common debt indicator is PPG, official creditors (INT, current US$) with the frequency of 116

3.8 Other Key Debt Trends​

3.8.1 Top 5 countries with the most debt​


Code:
select country_name, sum(debt) as total_debt
from international_debt_with_missing_values
group by country_name
order by total_debt desc
limit 5;

Top five countries with the highest debts

Fig2: Average Debt per Indicator Category​

3.8.2 Five Countries with the Lowest Debt​


This excludes countries registering 0 debt****


Code:
select country_name, min(debt) as total_debt
from international_debt_with_missing_values
where debt> 0 
group by country_name
order by total_debt desc
limit 5;

Five countries with the least debt, excluding countries with 0 debt

Fig:5 Countries with the Lowest Debt​

3.8.3 Number of countries with missing debt values​


Code:
select count(debt) as missing_records
from international_debt_with_missing_values
where debt= 0;

Total number of countries where debt is 0 are 52

Conclusion​


Overall, the data suggests a significant dependence on external financing, with repayment pressures concentrated in a few major economies and vulnerable groups. This underlines the importance of careful debt management policies, diversification of financing sources, and sustainable borrowing strategies to reduce long-term risks.

Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top