R Application Programming Interface (API)
The R package ugatsdb
connects to a relational time series database and provides direct access to more than 5000 time series
available in the Macro Data Portal at various frequencies (daily, monthly, quarterly, annual CY and FY). These series broadly cover
of the 4 sectors of the economy (real, external, financial and fiscal) and also include various development indicators. They are sourced on a monthly basis
from the Bank of Uganda, UBOS, the Ministry of Finance, the IMF, and the World Bank. Data with a cross-sectional dimension such as census data or
trade-related panels are not available through the API but can be accessed via the Portal.
The API allows bulk download of entire datasets or query of individual series from one or more datasets.
provide information about the available data, analogous to the 'Data Catalog'
tab in the Portal. Dataset and series codes from these tables are needed to query data using the
The API is fully documented on the R help pages, calling
after installation. A small demonstration is provided below.
It should be noted that the API connects directly to a database, requiring remote connections to be permitted by the users firewall
(which may not be the case inside institutional networks that block all remote connections).
The package can be installed from the R console by executing the following line of R code:
The following code downloads daily interest rates data from the Bank of Uganda for the last 365 days. The dygraphs
library can be used to generate a dynamic chart of this data following easy conversion to extensible time series format.
package also provides functions
to reshape data from the API (by default the format is wide).
The database stores data at all frequencies in a 'Date' column. The function
can be used to generate various additional identifiers from the date variable
(by default year, quarter, fiscal year, quarter of fiscal year and month), which are useful for data manipulations tasks such as aggregation.