Overview
The GSS StatsBank API is built on PxWeb technology, a standard used by many statistical agencies worldwide. Think of the API like a file explorer on your computer: it has a hierarchy of “folders” (Databases and Levels) that eventually lead to “files” (Tables).Prerequisites
Before connecting to the API, ensure you have the required R packages installed:The
httr2 package handles HTTP requests and responses, while tidyverse is used for data manipulation tasks.Establishing the Connection
Define the Base URL
Start by setting up the base URL for the GSS StatsBank API:This creates a request object that you’ll use to interact with the API.
Test the Connection
Perform a simple request to verify the connection is working:This should return a list of available databases in the StatsBank system.
Understanding the API Structure
The GSS StatsBank API follows a hierarchical structure:- Root Level: Lists all available databases
- Database Level: Contains topic folders (e.g., “Water and Sanitation”, “Education”)
- Topic Level: Contains individual data tables (ending in
.px) - Table Level: Contains the actual data and metadata
Common Databases
Here are some frequently used databases available through the API:| Database | Description |
|---|---|
| PHC 2021 StatsBank | 2021 Population and Housing Census data |
| PHC2010 | 2010 Population and Housing Census data |
| GLSS7 | Ghana Living Standards Survey Round 7 |
| Annual Household Income and Expenditure Survey (AHIES) | Household income and expenditure data |
| Ghana Census of Agriculture (GCA) | Agricultural census data |
| Macroeconomic Indicators | Economic indicators and statistics |