IDEAS home Printed from
   My bibliography  Save this article

Speaking Stata: Distinct observations


  • Nicholas J. Cox

    () (Durham University, UK)

  • Gary M. Longton

    () (Fred Hutchinson Cancer Research Center, Seattle)


Distinct observations are those different with respect to one or more variables, considered either individually or jointly. Distinctness is thus a key aspect of the similarity or difference of observations. It is sometimes confounded with uniqueness. Counting the number of distinct observations may be required at any point from initial data cleaning or checking to subsequent statistical analysis. We review how far existing commands in official Stata offer solutions to this issue, and we show how to answer questions about distinct observations from first principles by using the by prefix and the egen command. The new distinct command is offered as a convenience tool.

Suggested Citation

  • Nicholas J. Cox & Gary M. Longton, 2008. "Speaking Stata: Distinct observations," Stata Journal, StataCorp LP, vol. 8(4), pages 557-568, December.
  • Handle: RePEc:tsj:stataj:v:8:y:2008:i:4:p:557-568

    Download full text from publisher

    File URL:
    Download Restriction: no

    File URL:
    Download Restriction: no

    References listed on IDEAS

    1. Nicholas J. Cox, 2002. "Speaking Stata: How to move step by: step," Stata Journal, StataCorp LP, vol. 2(1), pages 86-102, February.
    Full references (including those not matched with items on IDEAS)


    Citations are extracted by the CitEc Project, subscribe to its RSS feed for this item.

    Cited by:

    1. Nicholas J. Cox, 2008. "Stata tip 71: The problem of split identity, or how to group dyads," Stata Journal, StataCorp LP, vol. 8(4), pages 588-591, December.
    2. Ignace De Vos & Gerdie Everaert & Ilse Ruyssen, 2015. "Bootstrap-based bias correction and inference for dynamic panels with fixed effects," Stata Journal, StataCorp LP, vol. 15(4), pages 986-1018, December.
    3. Nicholas J. Cox, 2009. "Speaking Stata: Rowwise," Stata Journal, StataCorp LP, vol. 9(1), pages 137-157, March.

    More about this item


    distinct; by; egen; distinctness; uniqueness; data management;


    Access and download statistics


    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:557-568. 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) or (Lisa Gilmore). General contact details of provider: .

    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 CitEc recognized a reference but did not link an item in RePEc 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 RePEc Author Service 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.

    IDEAS is a RePEc service hosted by the Research Division of the Federal Reserve Bank of St. Louis . RePEc uses bibliographic data supplied by the respective publishers.