Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Speaking Stata: by varlist


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Speaking Stata: by varlist
Date   Mon, 24 Jun 2002 11:05:52 +0000

> >>I have a data set, and I know by the ID variable there is no duplicates,
> >>because if I use
> >>
> >>bys ID: gen count=_N
> >>tab count
> >>
> >>I get count all equal to 1.
> >>
> >>However, if I use
> >>
> >>bys ID: list varlist if N>1
> >>
> >>Stata starts to list every observation from the top.
> >>
> >>Why is this happening?
> >
> >One explanation is that your code:
> >bys ID: list varlist if N>1
> >
> >should be
> >
> >bys ID: list varlist if _N>1
> >
> >Fred
>
> This actually doesn't make any difference.  Either syntax gives you the
> same result, as I confirmed with my own data after I noticed the same
> thing.  I think in the syntax above, _N is not found, so that for every
> observation _N>1.

This works as it should for me. In fact the command produces the header for 
each group but does not produce output within each group:

.. by index, sort: list if _N >1

_______________________________________________________________________________
-> index = 1

_______________________________________________________________________________
-> index = 2

_______________________________________________________________________________
-> index = 3

_______________________________________________________________________________
-> index = 4

etc.

regards,
uli



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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