separating string variables for pregnancy complication questions [message #11679] |
Thu, 26 January 2017 22:09 |
chr8850
Messages: 20 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 |
schoumaker
Messages: 66 Registered: May 2013 Location: Belgium
|
Senior 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
|
|
|
|