The DHS Program User Forum      
Discussions regarding The DHS Program data and results
Home » Topics » Reproductive Health » separating string variables for pregnancy complication questions
separating string variables for pregnancy complication questions [message #11679] Thu, 26 January 2017 22:09 Go to next message
chr8850
Messages: 14
Registered: July 2016
Member
Hi there,

I am working with the Afghanistan 2010 Mortality Survey. In the women's file there are a few questions (q406 and q427) from the maternity section that ask women what problems they had when they first had antenatal care and during delivery. As multiple responses are allowed the variable in the dataset is a long string of letters and there are several combinations of these (attached here a snapshot of part of the table generated when i run tab). Could you please advise on how these can be separated out in STATA so that I can count how many women had each of the symptoms mentioned for each pregnancy?

thanks

Ali
Re: separating string variables for pregnancy complication questions [message #11680 is a reply to message #11679] Fri, 27 January 2017 03:41 Go to previous messageGo to next message
schoumaker is currently offline  schoumaker
Messages: 31
Registered: May 2013
Location: Belgium
Member
Hello,
The few lines below will create new dichotomous variable (Q406_A, q406_B,...). There may be other ways to do this, but this should work.
Best,
Bruno


***

local resp "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
foreach var of local resp {
gene q406_`var'=1 if regexm(q406,"`var'")==1
replace q406_`var'=0 if regexm(q406,"`var'")!=1 & q406!=""
}


Bruno Schoumaker
Centre for Demographic Research
Université catholique de Louvain
Re: separating string variables for pregnancy complication questions [message #11833 is a reply to message #11680] Wed, 15 February 2017 20:25 Go to previous message
chr8850
Messages: 14
Registered: July 2016
Member
Many thanks Bruno, that worked perfectly
Previous Topic: DECOMPOSING ERREYGERS CONCENTRATION INDEX - STATA...
Next Topic: STATA recode for assistance during delivery SLDHS
Goto Forum:
  


Current Time: Fri Oct 20 04:33:08 Eastern Daylight Time 2017