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
Estrella Gomez <[email protected]>
To
[email protected]
Subject
Re: st: tag by category
Date
Fri, 4 Oct 2013 10:33:45 +0200
Thank you very much!
2013/10/4 Nick Cox <[email protected]>:
> 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/
*
* 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/