Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: cut and paste spouse's income


From   [email protected]
To   [email protected]
Subject   RE: st: cut and paste spouse's income
Date   Wed, 30 Jun 2004 06:57:01 -0500

How about:

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 household person married income spouse_income, ab(20)

Which gives:

. l

     +--------------------------------------------------------------------+
     | houseid   person      r00   r01       r02       r03   r04   income |
     |--------------------------------------------------------------------|
  1. |      24        1                                        .       10 |
  2. |      24        2   spouse                               .        5 |
  3. |      24        3      son   son                         .        6 |
  4. |      24        4      son   son   brother               .        2 |
  5. |      24        5      son   son   brother   brother     .        4 |
     |--------------------------------------------------------------------|
  6. |      25        1      son   son                         .        6 |
  7. |      25        2      son   son   brother               .        2 |
  8. |      25        3   spouse                               .        5 |
  9. |      25        4      son   son   brother   brother     .        4 |
 10. |      25        5                                        .       10 |
     +--------------------------------------------------------------------+

. gen married = 2 if r01 == "" & r00 == "spouse"
(8 missing values generated)

. replace married = 1 if married ==. & r01 == ""
(2 real changes made)

. sort house married

. by houseid : gen spouse_income = income[2] if married == 1
(8 missing values generated)

. by houseid : replace spouse_income = income[1] if married == 2
(2 real changes made)

. list hou per married inc spouse_in

     +------------------------------------------------+
     | houseid   person   married   income   spouse~e |
     |------------------------------------------------|
  1. |      24        1         1       10          5 |
  2. |      24        2         2        5         10 |
  3. |      24        4         .        2          . |
  4. |      24        3         .        6          . |
  5. |      24        5         .        4          . |
     |------------------------------------------------|
  6. |      25        5         1       10          5 |
  7. |      25        3         2        5         10 |
  8. |      25        4         .        4          . |
  9. |      25        1         .        6          . |
 10. |      25        2         .        2          . |
     +------------------------------------------------+


 
Hope this helps,
Scott


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index