Does anyone know a simple way to copy the contents of a variable for one
observation over to a new variable in a different observation? For
instance, suppose I have a data set consisting of married couples. I have
three variables: a household identifier (hhid), a person identifier within
the household (person) which equals one or two, and a variable for income
(income). I want to create a new variable for spouse's income
(inc_spouse). To do so I code the following:
by hhid, sort: gen inc_spouse=income[2] if person==1;
by hhid: replace inc_spouse=income[1] if person==2;
This is a cumbersome process, which becomes more complicated for more
complex data set--if, for instance, the households contain different
numbers of people. In addition, with more complicated data, it becomes
more difficult to check whether or not the coding is done correctly.
Does anyone know a simple way of copying the contents of a variable for
one observation over to a new variable in a different observation? It
seems like something that would be done frequently enough that there
should be some simple way of doing it. Any help is much appreciated.
Rebecca
*
* 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/