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: tag by category


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: tag by category
Date   Fri, 4 Oct 2013 09:25:06 +0100

egen tag = tag(id country)
egen ntags = total(tag), by(country)
tabdisp country, cell(ntags)

The principle is kick-yourself-easy. The first command assigns 1 to
precisely one observation for each combination of -id- and -country-
and 0 otherwise. The second command adds those values up by -country-.
Adding 1s, one for each instance, is usually just called counting. The
0s naturally do not affect the total.

For the fullest (because only) review of this generic problem, see

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

which is downloadable. See
http://www.stata-journal.com/sjpdf.html?articlenum=dm0042

Nick
[email protected]

On 4 October 2013 08:42, Estrella Gomez <[email protected]> wrote:

> I have a panel that contains 16030 different ids per 28 countries. I
> would like to know how many different ids do I have per country,
> because not all the ids are available in all countries. I have tried
> the command:
>
> by country: egen tag=tag(id)
>
> But tag is not compatible with by. Does anybody know any easy way of doing this?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index