Using DBnomics with Stata

In this blog, I will show you in a few simple steps how to use the database aggregator DBnomics to retrieve some data with Stata. In a previous blog, I showed you how to use FRED with Stata. Like FRED, this database aggregator gathers an impressive number of providers (87 providers to date) and almost 950,000,000 unique series (to date) coming from more than 24,000 databases (to date). DBnomics and FRED are complementary. I would say that FRED is more focused on the US economy and DBnomics has more important international dimension. Consequently, if you are more interested in the US economy, you should use FRED. However, if you are more interested in the World economy, you should use DBnomics.

We start with the installation of some important packages, we will download three programs from SSC

ssc install dbnomics

ssc install libjson

ssc install moss

The dbnomics package has been made by Simone Signore and the source code is available on GitHub, besides a rather self-explanatory documentation is available on the website of the 2019 Stata Users Group meeting, which took place in London.

(A) The first step is to find the identifier of the series. For example, I could choose to search for “general government debt” in the homepage of DBnomics. You will find 274 datasets. I will dig a little further to reach the latest update of the World Economic Outlook. I found the following identifier for the database, the latest release of the IMF’s World Economic Outlook: [WEO:2022-04] on the following page. Then, I will find the identifier for the series [GGXWDG] and for the unit [pcent_gdp]

(B) Now, I load the database, the latest edition of the World Economic Outlook

dbnomics data, pr(IMF) d(WEO:2022-04) clear

I have the structure of the database and the order of the dimension

If I want to import the series, I need to follow the order of the three dimensions separated by a dot, namely, country.topic.unit (weo-country.weo-subject.unit)

For example, if I want the series for France, I choose the country “FRA”, the topic of the series “GGXWDG_NGDP” and the unit “pcent_dgp” (note that the SDMX option is not supported by all the providers)

dbnomics import, pr(IMF) d(WEO:2022-04) ///
sdmx(FRA.GGXWDG_NGDP.pcent_gdp) clear

In general, we are more interested in multi-country analyses, you need to remove the country code “FRA”

dbnomics import, pr(IMF) d(WEO:2022-04) ///
sdmx(.GGXWDG_NGDP.pcent_gdp) clear

(C) Finally, I clean the data by removing the unnecessary information. I will have the data in long format and I export it in an Excel file

destring value, replace force

rename value grossdebt

order weo_country period grossdebt

encode weo_country, generate(code)

order code weo_country period grossdebt

drop period_start_day frequency dataset_code ///
dataset_name unit weo_subject indexed_at ///
provider_code series_code series_name series_num 

export excel using "grossdebt", sheetreplace firstrow(variables)

Further Reading

Sebastien Fontenay, 2017, Module to import data from statistical agencies using the SDMX standard, 2017 Paris Stata Users Group Meeting.

Joao Pedro Azevedo, 2011. WBOPENDATA: Stata module to access World Bank databases, Statistical Software Components S457234, Boston College Department of Economics, revised 02 Jul 2020.

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.