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 on April 23, and its replacement, is already up and running.

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

Re: st: Is -collapse- the Stata's fastest routine to summarize data sets?

From   Eric Booth <>
To   "<>" <>
Subject   Re: st: Is -collapse- the Stata's fastest routine to summarize data sets?
Date   Fri, 9 Jul 2010 00:36:36 +0000



When summarizing a large dataset, I've found the program that runs the fastest for me is -tabout- (from SSC).  
I don't know enough about what's going on in the tabout adofile to know why it's faster and it may not be faster for all types of summary tables, but I when I changed from -collapse-/-contract- to -tabout- in my do-file there was a huge time savings when working with a dataset of about 60 million obs.

For an illustration, here's a speed comparison for creating the same summary table with these 2 packages: 

clear all
** |  change -set mem- and -expand- below to fit your system  | **
set mem 12g
sysuse auto
	cap which tabout
	if _rc ssc install tabout

**create a large dataset**
expand 950000
desc, sh    
	recode rep78 (.=9)

**test collapse vs. tabout**

//  1. collapse
ds make rep78, not
local vars `r(varlist)'
timer clear 1
timer on 1
collapse (sum) `vars'  , by(rep78)
timer off 1
save master

//  2.  tabout
local vars: subinstr local vars " " " sum ", all
di "`vars'"
timer clear 2
timer on 2
tabout rep78 using test.xls, replace sum c(sum `vars') 
timer off 2

**make sure these are creating the same summary tables**
cf _all using master.dta, verbose all
timer list

  timer list
   1:    240.41 /        1 =     240.4130
   2:      0.43 /        1 =       0.4340

4 minutes for -collapse- versus less than a second for -tabout- summary table (using Stata 11.1 MP on Mac OS X).
Good luck.

~ Eric
Eric A. Booth
Public Policy Research Institute
Texas A&M University
Office: +979.845.6754

On Jul 8, 2010, at 9:02 AM, Tiago V. Pereira wrote:

> Dear Statalister,
> I am eager to know any faster alternatives to -collapse-, because I have
> to summarize relatively large data sets for a simulation study. -profiler-
> is telling me that most of the computation burden comes from -collapse-.
> Do you know (have) any faster alternative? Perhaps a plug-in?
> Thanks!
> Tiago
> *
> *   For searches and help try:

*   For searches and help try:

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