Scott Merryman replied to Benoit Dulong 
 
> > Is it possible (change the program) to get nearest to 
> work with by ?
> Rather than changing the program you could use foreach to 
> call -nearest- for
> each group.
> 
> Example:
> 
> levels id, local(levels)
> foreach l of local levels {
>      nearest x y if idrep == `l' , id(idpoint`l') dist(h`l')
>       }
> 
To expand a bit on Scott's reply: 
You can do it. See help -byable-. 
It's not on my agenda, even though it is  
a minor change. As Michael Blasnik has 
pointed out previously, -nearest- is not nearly 
so fast as a program he wrote himself. 
Therefore, it's that program which should 
be improved (if it doesn't support this 
already).  
Meanwhile, as Scott indicated, -foreach- 
with -levels- is one way to -by:-it-yourself. 
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/