Optimizing Stata for Analysis of Large Data Sets
As with most programming languages, there can be multiple ways to do a task in Stata. Using modern CPUs with adequate memory, most Stata data processing commands run so quickly on small- or moderate-sized data sets that it is impossible to tell whether one command performs more efficiently than another. However, when analyzing large data sets such as the Nationwide Inpatient Sample (NIS), with about 8 million records per year (~3.5GB), this choice can make a substantial difference in performance. Using the Stata timer command, we performed standardized benchmarks of common programming tasks, such as searching the NIS for a list of ICD-9 codes, converting string data to numeric, and putting numeric variables in categories. For example, the inlist function can achieve significant performance gains compared to the equivalent “var==exp1 | var==exp2” notation (38% improvement) or using foreach loops (300% improvement). Using the real and subinstr functions to remove characters from strings and convert them to numbers is about 20 times faster than the destring command. The inlist, inrange, and recode functions also perform considerably better than the equivalent recode commands (13-70 times faster), especially for string variables, and are often easier to write and to read.
Year of publication: |
2013-08-01
|
---|---|
Authors: | Canner, Joseph ; Schneider, Eric |
Institutions: | Stata User Group |
Saved in:
freely available
Saved in favorites
Similar items by person
-
bipolate: A Stata Command for Bivariate Interpolation with Particular Application to 3D Graphing
Canner, Joseph, (2014)
-
Nonstandard Deviation: Making the Global Local
Pagano, Marcello, (2014)
-
Binned Scatterplots: introducing -binscatter- and exploring its applications
Stepner, Michael, (2014)
- More ...