How about this:
gen married = 2 if r01 == "" & r00 == "spouse"
replace married = 1 if married ==. & r01 == ""
sort house married
by houseid : gen spouse_income = income[2] if married == 1
by houseid : replace spouse_income = income[1] if married == 2
list house person married income spouse_income, ab(20)
Which gives:
+-----------------------------------------------------+
| houseid person married income spouse_income |
|-----------------------------------------------------|
1. | 24 1 1 10 5 |
2. | 24 2 2 5 10 |
3. | 24 5 . 4 . |
4. | 24 4 . 2 . |
5. | 24 3 . 6 . |
|-----------------------------------------------------|
6. | 25 5 1 10 5 |
7. | 25 3 2 5 10 |
8. | 25 1 . 6 . |
9. | 25 4 . 4 . |
10. | 25 2 . 2 . |
+-----------------------------------------------------+
Hope this helps,
Scott
----- Original Message -----
Hi guys,
I have a problem which I have sorted, but I can't help but wonder if there are
better ways of doing it.
I have a data set where I observe the relationship between people within a
household and their income. I want to create a variable which carries the value
of the spouse's income.
In this example of a household with 5 people, person 1 is the head of the
household, person 2 is his spouse, person 3 is his son. Person 4 is the son of
person 1 and 2, and the brother of person 3 and 5, so on and so forth. Since
person 1 and person 2 are man and wife, cutting and pasting their respective
income into each other's spouseinc is pretty straight forward.
houseid person r00 r01 r02 r03 r04 income spouseinc
24 1 . . . . . 10 5
24 2 spouse . . . . 5 10
24 3 son son . . . 6 .
24 4 son son brother . . 2 .
24 5 son son brother brother . 4 .
However, the couple could be placed anywhere in the list. The person records
the sequence of the person being interviewed. Wife could be the 3rd to be
interviewed, man could be the 5th, etc.
<snip>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/