Steven Fraser
> > I am interested in obtaining the standard deviation for a 
> particular
> > variable with groups determined by another variable.  
> Essentially I would
> > like to combine the 'egen std()' function with the 'by' 
> construct which is
> > not allowed.  Is there an alternative to using collapse 
> (I would prefer not
> > to change the dataset) or having to introducing a matrix?
Scott Merryman
> Or, if you want the standard deviation as a variable you could:
> 
> levels class, local(levels)
> gen std = .
> foreach l of local levels {
>     qui sum mpg if class == `l'
>     qui replace std = r(sd) if class ==  `l'
>       }
> 
> You will need Nick Cox's -levels- (ssc install levels)
Scott's solution is fine (thanks for the plug), 
but it also seems from Steven's wording that 
-egen, sd()- will do what he wants (reference to -std()- 
is a red herring here). 
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/