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

RE: st: speed question: -collapse- vs -egen-

From   "Nick Cox" <>
To   <>
Subject   RE: st: speed question: -collapse- vs -egen-
Date   Mon, 28 Apr 2008 13:28:14 +0100

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. 


Michael Blasnik

You can gain some speed in regular Stata code by not generating a
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:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index