Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Overriding a loop if 0 observations using tabstat


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Overriding a loop if 0 observations using tabstat
Date   Tue, 27 Apr 2010 19:32:13 +0100

Apart from any question of a contest (I am happy to come last in this
kind of game), it's interesting, although not surprising, that -count-
retains a strong relative advantage on _better_ machines. 

Nick 
n.j.cox@durham.ac.uk 

Jeph Herrin

t=48.90; t=60.45; t=72.30. :>

Martin Weiss wrote:
> 
> t=100.28; t=207.58; t=241.55. :-)

Nick Cox
 
> Good question. I decided to do some timings to support -- or rebut --
my
> feeling that -count- which just counts should be faster than
-summarize,
> meanonly- which does other stuff too and in turn than -summarize-
which does
> other stuff too. But although that's the order the timings are closer
than I
> guessed. Still, doing anything the quickest way does no harm and may
give
> valuable speed-up for large problems. 
> 
> Here is one test script. Compare your experiences: 
> 
> clear
> set obs 100000
> set seed 2803
> gen y = runiform()
> set rmsg on
> 
> qui forval i = 1/10000 {
> 	count if y > 0.5
> }
> 
> qui forval i = 1/10000 {
> 	su y if y > 0.5, meanonly
> }
> 
> qui forval i = 1/10000 {
> 	su y if y > 0.5
> }
> 
> My timings were t=187.49; 254.49; 313.38, which no doubt shows up the
> Mesolithic age of my machine. 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> Martin Weiss
> 
> " As a small detail of efficiency, I would always recommend -count-
rather
> than -summarize- for the purpose here."
> 
> My earlier code did use -count-... What makes this thing more
efficient,
> though? Both are built-in, so they probably enjoy a big advantage over
> everybody else anyway. So I guess the reason for your preference is
the fact
> that -count- calculates fewer results than -su, mean-?
> 

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index