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

From |
Dan Blanchette <dan.blanchette@duke.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: What's the added value of having -in- subset the data before -if- does? |

Date |
Wed, 4 Feb 2009 10:27:52 -0500 (EST) |

. sysuse auto . list if foreign == 1 in 1/10 lists no observations because in the first 52 observations foreign == 0.

/* WHERE subsets the data before OBS subsets the data */ PROC PRINT DATA= SASHELP.SHOES(WHERE=(STORES < 10) OBS = 10); RUN; So, the above code lists the first 10 observations where (STORES < 10). I can't think of any situation where I would want to know how many times a certain condition exists in the first X observations. Do others ever need to know that?

. list if sum((foreign == 1)) <= 10

You could get a range of observations as well: . list if inrange(sum((foreign == 1)),2,11) I may decide always to use this since: . list if sum((foreign == 1)) <= 100 will also work despite the fact there aren't 100 observations in the data. I'll never again get the error message: Obs. nos. out of range r(198); My previous solution was to: preserve keep if foreign == 1 local nobs = 10 if _N < `nobs' local nobs = _N list in 1/`nobs' restore Thoughts? Dan Blanchette Research Associate Center of Entrepreneurship and Innovation Duke University's Fuqua School of Business Durham, NC USA dan.blanchette@duke.edu * * 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**:**st: RE: What's the added value of having -in- subset the data before -if- does?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: AW: What's the added value of having -in- subset the data before -if- does?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: RE: Using Value Labels to Label Variables** - Next by Date:
**Re: st: Possible bug with Mata binomialp and variable argument** - Previous by thread:
**st: Inserting a number into existing study ids** - Next by thread:
**st: AW: What's the added value of having -in- subset the data before -if- does?** - Index(es):

© Copyright 1996–2023 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |