Statalist


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

RE: st: how to identify unique id variables within groups?


From   Maarten buis <[email protected]>
To   stata list <[email protected]>
Subject   RE: st: how to identify unique id variables within groups?
Date   Wed, 20 May 2009 10:12:48 +0000 (GMT)

--- Jia Xiangping wrote:
> For a datafile like :
> id                    var1
> 1			1
> 1			2
> 1			3
> 2			1
> 2			2
> 2  		        1
> 
> I expect to check whether the value of "var1" within
>  one group of "id" is unique -- i.e. in group 2, the
> values are not unique. 

_N in combination with -bys- gives the total number of 
observations withing each group defined by the variables
in -bys-. So if var1 uniquely identifies individuals 
within id, than _N within -bys id var1- should always be 
1, and any duplicates will be identified with _N larger 
than 1. So you can do something like this:

bys id var1: gen byte duplicates = _N > 1
list id var1 if duplicates == 1

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index