Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Creating a unique identification number within a group


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Creating a unique identification number within a group
Date   Wed, 7 Aug 2013 16:46:13 +0100

Yes. Something like

bysort a (b c) : gen u = sum(b != b[_n-1] | c != c[_n-1])

See also http://www.stata.com/statalist/archive/2008-12/msg00616.html
Nick
[email protected]


On 7 August 2013 16:24, Tunga Kantarcı <[email protected]> wrote:
> Hello,
>
> I have three variables (a, b, c) which together uniquely identify a
> certain characteristic (call it u). I create a unique identification
> number from these three variables using the code
>
> egen u = group(a b c) and this gives:
>
> a b c u
> 1 2 3 1
> 1 2 4 2
> 1 2 4 2
> 9 2 3 3
> 9 2 4 4
> 9 2 4 4
>
> However what I would like to have is that for each "a", "u" starts
> from 1 so that I get:
>
> a b c u
> 1 2 3 1
> 1 2 4 2
> 1 2 4 2
> 9 2 3 1
> 9 2 4 2
> 9 2 4 2
>
> Of course in this case u is not a unique identifier in the whole
> dataset, but it is so within each a. Could I achieve this?
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index