Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: matching variable values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: matching variable values
Date   Fri, 25 Aug 2006 13:35:31 +0100

You can do this in place: 

gen MomHeight = . 

levelsof ID, local(ids) 

qui foreach id of local ids { 
	su Height if ID == `id', meanonly 
	replace MomHeight = r(min) if MomId == `id' 
}

There might be a limit on the application 
of that with really big datasets. 

There is probably a -merge- solution to this 
as well. It would be cuter than this if it existed. 

Nick 
[email protected] 

Gregor Franz
 
> I would like to match the values of one variable to the values of 
> another variable and then create a third variable. Here is 
> the basic setup:
> 
> ID      MomID      Height      MomHeight
> 1         .                  5                  .
> 2         1                 6                  5
> 3         .                  6                  .
> 4         1                  5.5               5   ...
> 
> MomHeight is the variable I want to create. It seems straightforward, 
> but I just can't come up with the right code.

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