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