Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: BASIC QUESTION - counts of counts


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: BASIC QUESTION - counts of counts
Date   Fri, 22 Jul 2011 14:15:37 -0500

For a solution with the same dataset:

egen tag = tag(State County)
egen freq = total(tag), by(State)
egen tag2 = tag(State)
l State freq if tag2

See also for a discussion of principles

SJ-8-4  dm0042  . . . . . . . . . . . .  Speaking Stata: Distinct observations
        (help distinct if installed)  . . . . . .  N. J. Cox and G. M. Longton
        Q4/08   SJ 8(4):557--568
        shows how to answer questions about distinct observations
        from first principles; provides a convenience command

Nick

On Fri, Jul 22, 2011 at 1:59 PM, Ben Hoen <[email protected]> wrote:
> Can someone help me to produce a table that counts the number of unique
> occurrences of a group inside another group?
>
> For example assume I had the following table:
>
> Number  State   County
> 1               NY      Madison
> 2               NY      Madison
> 3               PA      Somerset
> 4               NY      Oneida
> 5               PA      Somerset
> 6               PA      Wayne
> 7               PA      Luzerne
>
> I want to produce a table like this:
> State   County
> NY      2
> PA      3
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index