Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: how to switch the values of a variable for two persons within the same household?


From   xueliansharon <xuelianstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: how to switch the values of a variable for two persons within the same household?
Date   Sat, 18 Aug 2012 17:21:14 -0700 (PDT)

Dear all,

I have a data file containing records for households with either 1 or 2
persons. I want to generate a new variable v2 based on an old variable v1,
and the values of the new variable v2 should satisfy the following
condition: 
If there are 2 persons within the household, then v2 should be constructed
by switching the values of v1 for the 2 persons, i.e. within each 2-person
household, v2[1] =v1[2] and v2[2]=v1[1]. 
If there is only 1 person within the household, v2 takes missing value.

Here is an example:
HHID        person ID       v1        v2
1             01                 1          3
1             02                 3          1
2             01                 2          .
3             02                10         55    
3             04                55         10

How to generate such v2 based on v1?

Thank you for your help in advance!

Best,
Sharon        



--
View this message in context: http://statalist.1588530.n2.nabble.com/how-to-switch-the-values-of-a-variable-for-two-persons-within-the-same-household-tp7580237.html
Sent from the Statalist mailing list archive at Nabble.com.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index