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]

st: Generating unique values from unique and duplicate cases


From   Tim Morris <[email protected]>
To   [email protected]
Subject   st: Generating unique values from unique and duplicate cases
Date   Mon, 17 Oct 2011 15:49:42 +0100

Hello,

I have created syntax to check for and label potential duplicate cases across 3 variables (two text and one numeric). the syntax is as follows:

sort var1 var2 var3
quietly by var1 var2 var3: gen dup = cond(_N==1,0,_n) if var1!=. | var2!="" | var3!=""

this results in a new variable (dup) which may read as follows through the cases: 0, 0, 0, 1, 2, 0, 0 (1 and 2 being duplicate cases the rest being unique). What i want to do is create a new variable (id) that assigns a unique id to each unique case and groups together the corresponding duplicates into the same id, so based upon the example above the results will be along the lines of:

dup	id
0 	1
0 	2
0 	3
1 	4
2 	4
0 	5
0 	6

I have played around with various code, searched online and spoken to other STATA users for help but cannot find a way to make STATA assign unique values for each 'group' of duplicates. Thanks in advance for any help.

regards,
tim morris

----------------------
Tim Morris, ALSPAC
[email protected]
0117 331 0022

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index