Hi, I have a family database similar to this one: https://www.stata.com/support/faqs/d...ng-properties/
While the examples were useful to me and, with the help from another thread, I was able to do what I wanted, I was hoping there was a simpler way to do this.
My data looks like this:
and I want to create two variables: Father_Age & Father_Sex
which will take the Sex and Age from the person 1 from each family for every member.
I was able to do this with this code:
but I was hoping to find a way to achieve this with one line per variable. Thanks!
While the examples were useful to me and, with the help from another thread, I was able to do what I wanted, I was hoping there was a simpler way to do this.
My data looks like this:
Family | Person | Sex | Age |
1 | 1 | 1 | 45 |
1 | 2 | 0 | 43 |
1 | 3 | 1 | 17 |
2 | 1 | 1 | 57 |
2 | 2 | 0 | 49 |
3 | 1 | 1 | 50 |
3 | 2 | 0 | 45 |
3 | 3 | 0 | 15 |
3 | 4 | 1 | 20 |
which will take the Sex and Age from the person 1 from each family for every member.
I was able to do this with this code:
Code:
bysort Family: gen Father_Age = Age if Person == 1 bysort Family: replace Father_Age = Father_Age[1] bysort Family: gen Father_Sex = Sex if Person == 1 bysort Family: replace Father_Sex = Father_Sex[1]

Comment