In this blog, we will see how to use with Stata and Python. I will rely 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 indicator maintained by the Freedom House (https://db.nomics.world/FH/CTRS).
Key takeaways:
- After the fall of the USSR, the Europe and Central Asia and the Subsaharan Africa region have known large improvements in their political rights scores;
- In the West Asia and North Africa region (the correct name for the Middle East and North Africa region) and the oil countries group, we did not witness the same improvements during the 1990s;
- After the Arab Spring, some improvements in their political rights scores are observed, but these progresses have not been preserved;
- This may be due to their Institutional Genes;
- Institutional Genes are fundamental institutional elements that self-replicate and guide institutional changes and are empirically identifiable.
- Using Python to download data from API links is faster than using Stata DBnomics package;
- ChatGPT 5 is pretty good at translating Stata DBnomics syntax into Python DBnomics syntax;
- The syntax to import data from the API link is very practical.
We are going to replicate the first step of the following blog, Merging datasets with different country codes with Stata with a different series, using Python, and reproduce the figure below:


The shortened code is commented at each steps below:
**# Python
// Python version with the API on the DBnomics (select columns) and create the exel file
python:
import dbnomics as db
api_link = ("https://api.db.nomics.world/v22/series/FH/CTRS?dimensions=%7B%22co_or_ter%22%3A%5B%22c%22%5D%2C%22indic%22%3A%5B%22pr%22%5D%7D&facets=1&format=json&limit=1000&observations=1")
df = db.fetch_series_by_api_link(api_link, max_nb_series=10000)
df[["Country - Territory","original_period","value"]].to_excel("Political.xlsx", index=False)
end
**# Use Stata to read the dataset
import excel Political.xlsx, firstrow clear
*ssc install kountry
kountry CountryTerritory, from(other) stuck marker
rename _ISO3N_ iso3c
drop MARKER
kountry iso3c, from(iso3n) to(imfn)
rename _IMFN_ imfcode
drop if imfcode==.
rename original_period period
rename value PR
rename CountryTerritory name
order imfcode name period
drop if name=="Yugoslavia"
drop if name=="Serbia and Montenegro"
drop if name=="USSR"
// 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 PRwe=PR if we==1
gen PReca=PR if eca==1
gen PReap=PR if eap==1
gen PRlac=PR if lac==1
gen PRssa=PR if ssa==1
gen PRmena=PR if mena==1
gen PRoil=PR if oil==1
gen PRemg=PR if emg==1
gen PRidc=PR if idc==1
lab var PR "Full Sample"
lab var PRemg "Emerging Markets"
lab var PRidc "Industrialized Countries"
lab var PRwe "Western Europe"
lab var PReca "Europe and Central Asia"
lab var PReap "East Asia and Pacific"
lab var PRlac "Latin America"
lab var PRssa "Subsaharan Africa"
lab var PRmena "West Asia and North Africa"
lab var PRoil "Oil Countries"
// Use lpgraph to draw time series graph with panel data
*ssc install lgraph
set scheme s1color
graph set window fontface "Palatino Linotype"
lgraph PR PReca PRssa PRmena period, wide ///
ti("Average Political Rights") xti("") yti("") ///
note("`Note: Data from the Freedom House.'") xline(2008 1990 2010) ///
text(6.5 2007 "{it:GFC}", box margin(small) fc(white)) ///
text(6.5 1990 "{it:USSR Fall}", box margin(small) fc(white)) ///
text(5 2014 "{it:Arab Spring}", box margin(small) fc(white)) ///
name(PR, replace)
graph export PR.png, as(png) width(4000) replace
Conclusion:
Somehow the democratic transition has been stopped in the WANA region after the Arab Spring. With Martin Paldam, we study that question in detail in a new working paper on the political capitalism in this region and oil countries, available here: http://www.martin.paldam.dk/Papers/GT-Main2/Nr8-OPEC-capitalism.pdf. According to Holcombe (2018), “Political capitalism is an economic and political system in which the economic and political elite cooperate for their mutual benefit.” More to come on that.
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
Paldam, M. (2021). The grand pattern of development and the transition of institutions. Cambridge University Press. https://www.cambridge.org/core/books/grand-pattern-of-development-and-the-transition-of-institutions/17EC8DBEC63474372A41FEAD13D7B5B1
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
Xu, C. (2025). Institutional Genes: Origins of China’s Institutions and Totalitarianism. Cambridge University Press. https://www.cambridge.org/core/books/institutional-genes/DFA81FF6743415B9BE95117D7E65CD60