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

Re: A simpler count question Re: st: RE: Re: Counts of different values in one variable by another variable


From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: A simpler count question Re: st: RE: Re: Counts of different values in one variable by another variable
Date   Fri, 26 Mar 2004 10:52:23 -0500

At 07:15 AM 3/26/2004 -0800, you wrote:
above).  My problem is that I -tab1- a variable but there are too many
values for it to run the frequency distribution.  I could use by, but that
could get very tedious with counting, and could be prone to error when I
add up across the by variable.  I expect there to be something on the
order of 3700 values, but I have to check to be sure.
One approach is to upgrade to Stata/SE, whose -tabulate- command can handle up to 12,000 rows. So you could do

. quietly tab x

and then grab r(r)

If the values are all integers, then the command -levels- (available from SSC) might do the trick for you.

Or, from first principles:

. bysort x: gen count = (_n==1)
. replace count = sum(count)
. sum count

and grab r(max)

--Nick Winter

--Nick Winter


--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601
*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index