I have a series of variables fam1 - fam14 that represent sex and age of all family members. They were entered as H45 or M35 (where H=male and M=woman, and their age after the letter). I need to separate the age from sex in order to run any analyses
I've figured out that I can go line by line, and make male1 - male14 to represent the sex of each family member and age1 - age14 to represent their age with the following commands:
gen male1 = regexs(2) if regexm(fam1, "(([A-Z]+)*([0-90 - 90-9]+))")
gen age1 = regexs(3) if regexm(fam1, "(([A-Z]+)*([0-90-90 - 9]+))")
However, I know this is rather labor intensive and feel like I should be able to do this with a loop, but can' seem to figure it out.
Any guidance would be greatly appreciated.
Thanks,
Taylor
I've figured out that I can go line by line, and make male1 - male14 to represent the sex of each family member and age1 - age14 to represent their age with the following commands:
gen male1 = regexs(2) if regexm(fam1, "(([A-Z]+)*([0-90 - 90-9]+))")
gen age1 = regexs(3) if regexm(fam1, "(([A-Z]+)*([0-90-90 - 9]+))")
However, I know this is rather labor intensive and feel like I should be able to do this with a loop, but can' seem to figure it out.
Any guidance would be greatly appreciated.
Thanks,
Taylor
Comment