Hi all,
I have a dataset with personal ID, date of birth, and their relationships with others. I want to create a birth order for each person, with value 1 for the eldest sibling.
In the sample dataset below,
Can anyone help?
Thanks a lot!
I have a dataset with personal ID, date of birth, and their relationships with others. I want to create a birth order for each person, with value 1 for the eldest sibling.
In the sample dataset below,
- Person 1 and person 3 are siblings. They live in different household.
- Person 4, 5, and 6 are another sibling pair. They live in the same household.
- Person 2 doesn't have any sibling.
| pid | hid | dob | sib1 | sib2 | birth_order |
| 1 | 111 | Jan2000 | 3 | -1 | 1 |
| 2 | 222 | Feb2001 | -1 | -1 | 1 |
| 3 | 333 | Mar2002 | 1 | -1 | 2 |
| 4 | 444 | Apr2003 | 5 | 6 | 1 |
| 5 | 444 | May2004 | 4 | 6 | 2 |
| 6 | 444 | Jun2005 | 4 | 5 | 3 |
Thanks a lot!
Code:
clear input float(pid hid) str7 dob float(sib1 sib2) 1 111 "Jan2000" 3 -1 2 222 "Feb2001" -1 -1 3 333 "Mar2002" 1 -1 4 444 "Apr2003" 5 6 5 444 "May2004" 4 6 6 444 "Jun2005" 4 5 end lab var pid "Personal ID" lab var hid "Household ID" lab var dob "Date of birth" lab var sib1 "Personal ID of sibling 1" lab var sib2 "Personal ID of sibling 2" label def sib_lab -1 Inapplicable, modify label values sib1 sib2 sib_lab

Comment