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

st: RE: referencing a specific cell


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: referencing a specific cell
Date   Wed, 7 Dec 2005 12:25:07 -0000

Kit's solution looks incomplete to me. 

I guess that "second" cannot be special 
unless observations are ordered within 
-id- in some important way, say by time. 

Thus observations must be kept in the 
same relative order within -id-, which is 
not guaranteed by Kit's code. One way to 
do it is 

sort household_id, stable 
by household_id: replace wage2 = wage1[2] if wage2 == .

If there were say a time variable -time-, then 

bysort household_id (time) : replace wage2 = wage1[2] if wage2 == .

Nick 
[email protected] 

Kit Baum
 
> Irina asks
> 
> Suppose my data has 2 observations per household and is organized as:
> 
> household_id	wage of person1		wage of person2
> 1			3			.			
> 1			5			.		
> 		
> 
> 2			6			.		
> 				
> 2			7			.			
> 
> I would like Stata to, whenever the wage of person 2 is missing, to  
> substitute into it the SECOND observation of the wage of person 1  
> within that household. So I would want the data to look like:
> 
> household id	wage of person1		wage of person2
> 1			3			5
> 1			5			5
> 
> 2			6			7
> 2			7			7
> 
> 
> bysort household_id: replace wage2 = wage1[2] if wage2 == .

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