Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: unique value count in several variables


From   "Wanli Zhao" <zhaowl@temple.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: unique value count in several variables
Date   Sat, 18 Jun 2005 16:17:12 -0400

Thanks, Nick. I looked into the suggestions and I think I might have
confused you on my problem. My panel data is like this:
Gvkey  psic  ssic  year  subno
1223   4767  4743  1999  1
1223   4767  4763  1999  2
1223   4757  4767  1999  3
1223   4767  4753  1999  4
1223   4777  4787  1999  5
1223   4767  4743  1999  6

Using command unique, I can count the distinct values of psic and ssic by
gvkey by year. So for psic it's 3 and for ssic it's 5. what I want is to
count the distinct values of both psic and ssic by gvkey by year. In this
case, it's 7 (4767, 4757, 4777, 4743, 4763, 4753, 4787). How to generate a
new variable for my purpose? Hope I'm clear now. Pls help.

Thanks.
Wanli Zhao

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Saturday, June 18, 2005 11:52 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: unique value count in several variables

By "unique" here I think you mean "distinct". 

Try -groups- from SSC. Or -egen, group()- and then tabulate. 

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

Wanli Zhao
 
> I have a simple question but got stuck on a simple solution. 
> I have a panel
> and let's say cross-section id is gvkey and time id is year. 
> There are two
> variables, say, primary sic and secondary sic. My aim to count the 
> unique value of sic in both variables by gvkey by year. I know the 
> 'by' thing is straightforward but is there a quick solution to count 
> the unique observation in both variables? I know the commands such as 
> unique, distinct and egenmore nvals. They work perfect for a single 
> variable.
> Also, on the
> webpage there is a explanation of the unique combination of two 
> variables and how to count that. I guess mine is different. Your help 
> is appreciated.

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


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