Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: use of count.


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: use of count.
Date   Thu, 18 Sep 2008 10:56:35 +0200

Try this:

**********
sysuse auto, clear
*tag the groups
egen groups=group(f rep)
levelsof groups, loc(gr)
*counts go into mycount var
g mycounts=.
*loop over the levels of the groups
foreach lev of loc gr{
count if gr==`lev'
replace mycounts=r(N) if gr==`lev'
}
*lets see what happened
sort f rep
l f re gro myco, sepby(f rep) noo
table rep f, c(freq mean myc)
**********


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ashim Kapoor
Sent: Thursday, September 18, 2008 10:48 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: RE: use of count.

Can you please clarify how I can do this Martin ?
> You probably cannot replace with the string count: if at all, you would
have
> to count first and the replace with the return value "r(N)".

Thank you,
Ashim.

On Thu, Sep 18, 2008 at 1:14 PM, Martin Weiss <martin.weiss1@gmx.de> wrote:
> You probably cannot replace with the string count: if at all, you would
have
> to count first and the replace with the return value "r(N)".
> Also try this:
>
> **********
> u auto, clear
> egen float mygroups = group(f rep78)
> by mygroups, sort : egen float mycount = count(mygroup)
> **********
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ashim Kapoor
> Sent: Thursday, September 18, 2008 9:34 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: use of count.
>
> Hello everyone,
>
> I have a question :
>
> I want to do :
>
> bysort state cnum cname : replace no_of_cand_in_state=count
>
> This does not work. could someone please tell me how do I fix this ?
>
> Thank you,
> Ashim.
> *
> *   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/
>
> *
> *   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/
>
*
*   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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index