Michael of course is just giving example code.
In many problems, you would need to take account not only of missings
(as here) but also of -if- and -in- restrictions. One of the reasons
that -egen- and -collapse- are slow is that, as Stas pointed out, they
check for -if- and -in- and do the right thing for you.
Nick
[email protected]
Michael Blasnik
You can gain some speed in regular Stata code by not generating a
separate
variable just to count the number of non-missings:
bysort rep78: gen mean=sum(price)/sum(price<.)
by rep78: keep if _n==_N
On my machine, this reduces the time required for the corrected Stas
code from
17.3 to 13.8 s.
*
* 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/