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

st: -collapse- versus homebrew


From   Chris Ruebeck <ruebeckc@lafayette.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: -collapse- versus homebrew
Date   Sun, 20 Feb 2005 17:34:37 -0500

When we generate bootstrapped standard errors and perform Monte Carlo analyses, it's useful to make the code as speedy as possible. So I thought about -collapse- for a moment and performed the following speed test listed below. The timing results follow it, showing that my homebrewed version was twice as fast as -collapse-.

I'm not surprised at this result---collapse bears lots of overhead---but I'm wondering if there any general rules to indicate when -collapse- might be faster, if ever. I do value debugging time if -collapse- shortens it for me, but in this case upfront debugging time would seem to be small compared to the total time spent actually running the bootstrap or Monte Carlo.

Thanks,
Chris

........
set rmsg on
quietly {
forvalues i = 1/20 {
use "`theWards'", clear
gen ward = floor(uniform()*`nWards') + 1
bys ward: gen totCount = _N
by ward: gen type1count = sum(type1)
by ward: gen type2count = sum(type2)
by ward: keep if _n==_N
}
}
quietly {
forvalues i = 1/20 {
use "`theWards'", clear
gen ward = floor(uniform()*`nWards') + 1
collapse (count) type1count=type1 type2count=type2 totCount=ones, by(ward)
}
......
. set rmsg on
r; t=0.00 16:55:23

. quietly {
r; t=13.74 16:55:51

. quietly {
r; t=26.84 16:56:19
*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index