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 member household survey


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Re: How to extract and recode variables in a multiple member household survey
Date   Fri, 11 Feb 2005 10:27:26 -0000

In addition, your example shows that you 
want to zap the originals once they have
been copies, so that you 
would need two extra lines in your 
loop: 

	replace S_`M' = . in `i' 
	replace A_`M' = . in `i' 

If I were doing this, I would -reshape-, as Friedrich
suggested. That would be easier if you used names S_0 
and A_0 rather than SA and MA. That way it would be 
easy to sort mothers to the start of each block of 
observations. 

Nick 
[email protected] 

n j cox
 
> 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'
> }
> 
>  >>> [email protected]
> 
> 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index