In this blog, we will see how to use with Stata and Python. I will rely on a previous blog showing how to use DBnomics with Stata. This time, we use the dbnomics package to import the newly Financial Development Index built by the International Monetary Fund (https://db.nomics.world/IMF/FDI).
Key takeaways:
- Financial Development has stalled after the global financial crisis in 2008-09;
- This partially reflects excess in the financial sphere in the 2000s for industrial countries;
- However, it will create some inefficiencies for emerging markets with underdevelopped financial markets;
- ChatGPT 5 is pretty good at translating Stata DBnomics syntax into Python DBnomics syntax;
- Using Python and Stata from the same do-file is pretty good;
- I plan to extend to other previous Stata blogs and integrate more Python in future blogs on coding.
We are going to replicate the first step of the following blog, Merging datasets with different country codes with Stata, using Python and reproduce the figure below:

The code is commented at each steps below:
// Clear the consol and the dataset
cls
clear
// Choose the dir folder (optional)
cd "C:\Users\jamel\Dropbox\stata\dbnomics_python"
**# Python
**# Only once locate and initiate python
python search
*python set exec "C:/Users/jamel/AppData/Local/Programs/Python/Python313/python.exe", permanently
**# Use python to install DBnomics
python:
import sys, subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "dbnomics"])
end
**# Downloads data from DBnomics
/*
// Stata version
dbnomics import, pr(IMF) d(FDI) ///
sdmx(A..FD_FD_IX) clear
*/
// Python version
python:
import dbnomics as db
df = db.fetch_series(
'IMF','FDI',
dimensions={'FREQ':['A'], 'INDICATOR':['FD_FD_IX']},
max_nb_series=10000
)
end
/*
python:
import sys, subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pandas"])
end
*/
// Create the excel file
python:
excel_filename = "FD_FD_IX.xlsx"
df.to_excel(excel_filename, index=False)
print("Saved:", excel_filename)
end
**# Use Stata to read the dataset
import excel FD_FD_IX.xlsx, firstrow clear
drop frequency provider_code dataset_code dataset_name ///
series_code series_name FREQ INDICATOR ///
Frequency Indicator
// Use kountry and perpare the dataset
*ssc install kountry
kountry REF_AREA, from(iso2c)
rename NAMES_STD name
kountry REF_AREA, from(iso2c) to(imfn)
rename _IMFN_ imfcode
replace name="United Arab Emirates" if imfcode==466
replace name="Serbia" if imfcode==965
drop if imfcode==.
drop period
drop original_value
rename original_period period
rename value FD
order imfcode name period
// Prepare the data
destring period, replace
xtset imfcode period
xtdes
// Create the country groups (requires the ado-file 'group_dummy')
rename imfcode cn
group_dummy
rename cn imfcode
gen FDidc=FD if idc==1
gen FDemg=FD if emg==1
lab var FD "Full Sample"
lab var FDidc "Industrial Countries"
lab var FDemg "Emerging Markets"
// Use lpgraph to draw time series graph with panel data
*ssc install lgraph
set scheme s1color
graph set window fontface "Palatino Linotype"
lgraph FD FDidc FDemg period, wide ///
ti("Financial Development") xti("") yti("") ///
note("`Note: Data from the IMF.'") xline(2008) ///
text(0.5 2008 "{it:GFC}", box margin(small) fc(white)) ///
name(FinDev, replace)
graph export FinDev.png, as(png) width(4000)
Further reading
Aizenman, J., & Ito, H. (2020). Global politics from the view of the political-economy trilemma, 7 Aug 2020, VoxEU.org, https://cepr.org/voxeu/columns/global-politics-view-political-economy-trilemma
Raciborski, R. (2008). kountry: A Stata Utility for Merging Cross-country Data from Multiple Sources. The Stata Journal, 8(3), 390–400. https://doi.org/10.1177/1536867X0800800305
2 Comments
[…] on three previous blogs showing how to use Using DBnomics with Stata and Python (World Bank Data), Using DBnomics with Stata and Python, and DBnomics with Stata. This time, we use the dbnomics package to import the Political Rights […]
[…] we will see how to use with Stata and Python. I will rely on two previous blogs showing how to use Using DBnomics with Stata and Python and DBnomics with Stata. This time, we use the dbnomics package to import the Trade Openness […]