Hi there. I have string data in the format described below. I want to generate a new variable "Event”, that extracts all parts of variable Life Event mentioned in the local event. I’ve created a table below with a column Event (column name highlighted in red) to demonstrate the output I’m hoping for. Is there anyway I can write a loop to extract, that loops over X and Y where X and Y are events in the local?
Code:
#delim ;
local event `""birth" "marriage" " graduated school" " graduated college" "divorce" ///
"death" "miscarriage" "child death" "';
#delim cr
ID |
Life Event |
1 |
marriage; 24apr2008 |
1 |
death, 6jun2015 |
2 |
birth |
2 |
graduated school |
2 |
marriage, death; 1985 |
3 |
marriage, graduated college; divorce, death |
|
What I am hoping to get:
ID |
Life Event |
Event |
1 |
marriage; 24apr2008 |
marriage |
1 |
death, 6jun2015 |
death |
2 |
birth |
birth |
2 |
graduated school |
graduated school |
2 |
marriage, death; 1985 |
marriage, death |
3 |
marriage, graduated college; divorce, death |
marriage, graduated college; divorce, death |
|
|
Thanks,
Karishma
0 Response to Loop to extract multiple strings specified in a local
Post a Comment