Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
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 njcoxstata@gmail.com On 7 August 2013 16:24, Tunga Kantarcı <tungakantarci@gmail.com> 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/