Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: "unique" with "by"


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: "unique" with "by"
Date   Wed, 19 Apr 2006 17:28:53 +0100

Shige Song is using a user-written program -unique-, 
installable from SSC. 

Please recall the request in the FAQ to 
explain non-official commands you are using. 

I am always fond of answers like David Harrison's that explain 
how -levelsof- can solve your problem, as -levelsof- is 
a command I like. But there are other alternatives. One is 
to use -distinct-, also from SSC, which does support
-by:-. 

bysort hhid: distinct id 

gets you there in one. 

Whether the problem is one of distinct or of unique
observations is discussed in a unique FAQ, which 
also explains how to tackle it from first principles: 

FAQ     . . . . . . . . . . . . . . . . . . .  Number of distinct observations
        4/02    How do I compute the number of distinct observations?
                http://www.stata.com/support/faqs/data/distinct.html

Nick 
n.j.cox@durham.ac.uk 

David Harrison
 
> levelsof hhid, local(lev)
> foreach h of local lev {
>     unique id if hhid==`h' /* make this "`h'" if hhid is string */
> }
 
Shige Song
 
> I want to get count of unique values of a variable and I want 
> to use it
> conjuction with "by" like this:
> 
> sort hhid
> by hhid: unique id
> 
> But unfortunately the UNIQUE command does not allow the use of "by".
> Are there other options? Thanks!

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index