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

st: egen .&.. std()


From   "Fraser, Steven" <[email protected]>
To   "Statalist (E-mail)" <[email protected]>
Subject   st: egen .&.. std()
Date   Sun, 19 Jan 2003 15:28:56 -0500

Statalisters -

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?

Assume:

Manuf 		Model		Class 		Mpg
Chevy		Tahoe		SUV		14
Toyota		Highlander	SUV		19
Toyota		Camry		Auto		23
Ford		F-150		P/U		17
etc.

I would like to capture the standard deviation of the mpg within a
particular class.

i.e.

sort class
by class: gen (or egen) mpgstd = std(mpg)

The error is:
. by obj: egen mpgstd = std(mpg)
egen ... std() may not be combined with by

This however, is not allowed.  Any thoughts or comments are greatly
appreciated.

Steve Fraser

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