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

st: RE: filling in values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: filling in values
Date   Mon, 20 Oct 2003 12:41:38 +0100

E.Rueckert
> 
> in the survey I am using the head of household gives info 
> about every member
> of  the household. I have created a variable via egen that 
> accounts for the
> number of children within the family. How do "fill in" for 
> the rest of the
> family, i.e. family 3 has 1 child and I want observation 5 
> and 6 to be equal
> to 1, for example.
> 
>                family     children        
>        1.         1          0          
>        
>        2.         2          0          
>        3.         2          0           
>        4.         2          0           
>        
>        5.         3          1          
>        6.         3          0           
> 
>        7.         4          0           
>        8.         4          2      
> 

I am not sure what your systematic rule is 
here. Let me guess that you trust the highest 
value reported within each family for # of children. 

If so, one way to do that is 

bysort family (children) : replace children = children[_N] 

but that could give the wrong answer if -children- is 
missing, as missing values will get sorted to the 
end of each family and overwrite any nonmissing values. 

This is always safe: 

egen maxchildren = max(children), by(family) 
replace children = maxchildren 

As you are in this territory, you could check 
out, or note for future reference:  
 
http://www.stata.com/support/faqs/data/anyall.html

http://www.stata.com/support/faqs/data/members.html

Nick 
[email protected] 

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