IDEAS home Printed from https://ideas.repec.org/a/tsj/stataj/v8y2008i4p540-553.html
   My bibliography  Save this article

A shortcut through long loops: An illustration of two alternatives to looping over observations

Author

Listed:
  • Ward Vanlaar

    (Traffic Injury Research Foundation, Ottawa)

Abstract

It is well known that looping over observations can be slow and should be avoided. The objective of this article is to discuss two alternative solutions to looping over observations that can be used to overcome a particular data-management problem of merging datasets in which unique key identifiers changed over time. The first alternative, mapch, which is introduced in this article, uses a combination of appending, indexing, and merging to solve the problem, while the second alternative uses repeated merging. Both solutions are much quicker than looping over observations. However, depending on the nature of the problem, one solution may work better than the other. It is argued that the use of such dataset-type manipulations may be suitable to overcome other data-management problems. More generally speaking, the issue that is addressed—searching for an alternative to looping over observations—may be common and illustrates the importance of balancing the costs of developing an efficient solution with the benefits accruing from that solution. Copyright 2008 by StataCorp LP.

Suggested Citation

  • Ward Vanlaar, 2008. "A shortcut through long loops: An illustration of two alternatives to looping over observations," Stata Journal, StataCorp LP, vol. 8(4), pages 540-553, December.
  • Handle: RePEc:tsj:stataj:v:8:y:2008:i:4:p:540-553
    as

    Download full text from publisher

    File URL: http://www.stata-journal.com/article.html?article=dm0041
    Download Restriction: no

    File URL: http://www.stata-journal.com/software/sj8-4/dm0041/
    Download Restriction: no
    ---><---

    Corrections

    All material on this site has been provided by the respective publishers and authors. You can help correct errors and omissions. When requesting a correction, please mention this item's handle: RePEc:tsj:stataj:v:8:y:2008:i:4:p:540-553. See general information about how to correct material in RePEc.

    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.

    We have no bibliographic references for this item. You can help adding them by using 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 RePEc Author Service profile, as there may be some citations waiting for confirmation.

    For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: Christopher F. Baum or Lisa Gilmore (email available below). General contact details of provider: http://www.stata-journal.com/ .

    Please note that corrections may take a couple of weeks to filter through the various RePEc services.

    IDEAS is a RePEc service. RePEc uses bibliographic data supplied by the respective publishers.