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, **statalist.org** is already up and running.

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

From |
"Cohen, Elan" <cohened@upmc.edu> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Listing the first 5 observations |

Date |
Wed, 29 Aug 2012 14:29:08 +0000 |

How about: bys age (random): l if _n<=5 HTH, - Elan -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Damian Finlayson Sent: Wednesday, August 29, 2012 10:23 To: statalist@hsphsun2.harvard.edu Subject: st: Listing the first 5 observations Hi, This seems like a relatively simple query but no matter which way I try I cannot get it to work. I am trying to randomly select a number of observations according a set criteria. Say I have 3 variables: var1, var2 and random. Var1 consists purely of unique values (such as names). Var 2 has groups/categories (e.g. age). Random consists of unique random numbers. I would like to get stata to sort each category (age) by a random number and then list the first 5 names for a given age say 49. The command I am trying to use is: list var1 if age == 49 but I cannot seem to amend this command so that only the first 5 observations (as per the random number) are listed. If I use in 1/5 it does not work as the first observation for age 49 could be the 53 observation the second at 114 and so on. If I ask for all observations I could end up with thousands of names being listed. Thanks in advance for your help, * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: RE: Listing the first 5 observations***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: Listing the first 5 observations***From:*Damian Finlayson <damian.finlayson@gmail.com>

- Prev by Date:
**Re: st: QUAIDS with demographic translation** - Next by Date:
**Re: st: Listing the first 5 observations** - Previous by thread:
**st: Listing the first 5 observations** - Next by thread:
**Re: st: RE: Listing the first 5 observations** - Index(es):