The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Dissemination and Capacity Strengthening » Application Programming Interface (API)  » Generate percent of respondents by background characteristics (Demographics using API)
Generate percent of respondents by background characteristics [message #24245] Mon, 28 March 2022 17:29 Go to next message
DHSuser_NY is currently offline  DHSuser_NY
Messages: 5
Registered: November 2019
Good afternoon,

The attached table was created in StatCompiler showing percent of respondents by background demographics(age,residence,marital and wealth) using the the link below which StatCompiler generates when you share the tables. Because this is a table we run quite frequently for different surveys, using the link was a real time-saver.,LB,RW&ucc=&ic =SV_BACK_W_PCW&scl=10000,9001,9002,9003,3001,3002,6001,6 002,6003,6004,6005,15000,15001,15002,15003,15004,16001,16002 &dt=0&pt=0&ss=1&levelRank=0&si=SV_BACK_W _PCW&sbv= .

I would like to extract the same data using API which I am fairly new to. The following call in Stata only gives me wealth and marital status because I have not been able to identify the needed variables for residence(urban/rural) and 5-year age groups. Does anyone know if this information can be extracted from API?

import delimited using ///
" &surveyYearEnd=2022&breakdown=national&indicator Ids=MA_MSTA_W_NMA,MA_MSTA_W_MAR,MA_MSTA_W_LTG,MA_MSTA_W_DIV, MA_MSTA_W_SEP,MA_MSTA_W_WID,MA_MSTA_W_UNI,MA_MSTA_W_MIS,HC_W IXQ_P_LOW,HC_WIXQ_P_2ND,HC_WIXQ_P_MID,HC_WIXQ_P_4TH,HC_WIXQ_ P_HGH,&selectSurveys=latest&returnfields=surveyId,DH S_CountryCode,CountryName,SurveyYear,SurveyYearLabel,SurveyT ype,FieldworkStart,FieldworkEnd,indicator,IndicatorID,value, shortname&f=csv&apiKey=GUTTMA-130129", clear

Thanks for your help.

[Updated on: Mon, 28 March 2022 17:30]

Report message to a moderator

Re: Generate percent of respondents by background characteristics-Resolved [message #24250 is a reply to message #24245] Tue, 29 March 2022 13:29 Go to previous message
DHSuser_NY is currently offline  DHSuser_NY
Messages: 5
Registered: November 2019
I was able to figure this out. Sharing Stata code in case it is useful for anyone else. I needed to use the background indicator for percent of women(SV_BACK_W_PCW) and specify breakdown = all. This gave me some categories I don't need like education and region, but I just deleted them in Stata.

* Background characteristics table for most recent surveys 2006-2022.
import delimited using " 6&surveyYearEnd=2022&breakdown=all&indicatorIds= SV_BACK_W_PCW,&selectSurveys=latest&returnfields=sur veyId,DHS_CountryCode,CountryName,SurveyYear,SurveyYearLabel ,SurveyType,FieldworkStart,FieldworkEnd,indicator,IndicatorI D,value,shortname,characteristiclabel,characteristicid,chara cteristiccategory,&f=csv&apiKey=GUTTMA-130129", clear

Previous Topic: Child health data
Next Topic: Source of contraception by method
Goto Forum:

Current Time: Mon Jun 27 11:25:41 Coordinated Universal Time 2022