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

Re: st: Re: How to extract and recode variables in a multiple memberhousehold survey


From   n j cox <n.j.cox@durham.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: How to extract and recode variables in a multiple memberhousehold survey
Date   Fri, 11 Feb 2005 09:09:00 +0000

Friedrich's advice is very good. Nevertheless here is one way to
do what you want:

gen SA = .
gen MA = .
qui forval i = 1/`=_N' {
	local M = Mom[`i']
	replace SA = S_`M' in `i'
	replace MA = A_`M' in `i'
}

>>> ra248@columbia.edu

The variables S_i, A_i represent characteristics of household member
i.  The column Mom gives me the underscored value of where the Mom's
characteristics are. For instance, in the first household, the mom's
characteristics are S_2 and A_2 cause Mom takes the value 2. In the
second household, Mom is in S_1 and A_1...

Id   Mom   S_1   A_1   S_2   A_2   S_3   A_3 ... S_46   A_46
1      2     0    24     0    22     1    12 ...   0      67
2      1     1    29     0    32     0     8 ...   .       .
.
.
20     3     1    76     0    75     0    46 ...   1      41
.
.

What I want to create is the following:

Id  Mom  S_1  A_1  S_2  A_2  S_3  A_3 ... S_46  A_46  SA   MA
1     2    0   24    .    .    1   12 ...    0    67   0   22
2     1    .    .    0   32    0    8 ...    .     .   1   29
.
.
20    3    1   76    0   75    .    . ...    1    41   0   46




*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index