Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: RE: Duplicates order tagging


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Duplicates order tagging
Date   Fri, 28 Oct 2011 08:21:52 +0100

See also for related tricks

FAQ     . . . . . . . . . . . . . . . . . . . . . . Creating group identifiers
        . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and W. Gould
        3/01    How do I create individual identifiers numbered
                from 1 upwards?
                http://www.stata.com/support/faqs/data/group.html

On Fri, Oct 28, 2011 at 7:34 AM, Jesper Lindhardsen
<JESLIN01@geh.regionh.dk> wrote:
> Try
>
> bysort letter: gen order = _n
>
Ben Hoen

> If I have a set that contains the following values:
>
>        letter
> 1.      A
> 2.      A
> 3.      A
> 4.      B
> 5.      B
> 6.      C
>
> I can use .duplicates tag, g(freq) to generate a count of the
> duplicates:
>
>        letter  freq
> 1.      A       3
> 2.      A       3
> 3.      A       3
> 4.      B       2
> 5.      B       2
> 6.      C       1
>
> But I would also like to generate an order variable (e.g., " order")
> that
> increases for each successive iteration of the variable.  Such as:
>
>        letter  freq    order
> 1.      A       3       1
> 2.      A       3       2
> 3.      A       3       3
> 4.      B       2       1
> 5.      B       2       2
> 6.      C       1       1
>
> Is there an easy way to do that?

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index