Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: how to identify unique id variables within groups?
Date   Wed, 20 May 2009 12:13:22 +0200

<> 

Just check whether the standard deviation of the variable in question differs from zero, then:


*************

clear*
set obs 1000

//id
gen id=_n
//10 periods
expand 10
bys id: gen time=_n
xtset id time

//constant
bys id: gen byte myvar=runiform()<0.3

//but not for some...
replace myvar=cond(runiform()<0.1, 0, 1)

//Check for uniqueness
bys id:egen groupsd=sd(myvar)

//get dummy for uniqueness
gen byte unique=groupsd==0
la def unique 0 "not unique" 1 "unique" 
la val unique unique
drop groupsd

l in 1/100, noo sepby(id)
xttab unique
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Jia Xiangping
Gesendet: Mittwoch, 20. Mai 2009 11:55
An: statalist
Betreff: st: how to identify unique id variables within groups?

Dear all,

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. For a
non-grouped datafile, syntax like -isid- or -duplicates- is able to do
the work. But none of them works when combining with -by-.  Is there
any approach to check the unique  value within groups?

Thanks.



-- 
Xiangping Jia
*
*   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/


*
*   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