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.
When requesting a correction, please mention this item's handle: RePEc:boc:norl13:10. See general information about how to correct material in RePEc.
For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: (Christopher F Baum)
If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.
If references are entirely missing, you can add them using this form.
If the full references list an item that is present in RePEc, but the system did not link to it, you can help with this form.
If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your profile, as there may be some citations waiting for confirmation.
Please note that corrections may take a couple of weeks to filter through the various RePEc services.