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
[email protected]
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/