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: Generating unique values from unique and duplicate cases
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: Generating unique values from unique and duplicate cases
Date
Mon, 17 Oct 2011 17:15:54 +0100
I can see why Sergio and Richard answered as they did, but their answers are different. That is, your question remains ambiguous.
Did you check out -duplicates-.
Nick
[email protected]
Sergio Alvarez
==============
I don't know if this is what you need, but I know this will give you
unique values for each value of 'dup':
sort dup id
by dup: gen new_id = _n
then if you sort by id I think you'll get the observation in the order
you want.
Richard Goldstein
=================
if I understand what you want, use the -egen- command with the group function; e.g.,
egen id=group(var1 var2 var3)
Tim Morris
==========
> 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.
*
* 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/