Statalist


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

Re: st: use of count.


From   Johannes Geyer <JGeyer@diw.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: use of count.
Date   Thu, 18 Sep 2008 11:02:24 +0200

You could try the following:

bysort year state cnum: gen     x = _n == 1
by     year state     : replace x = sum(x)
by     year state     : replace x = x[_N]

a solution that is described here:

http://www.stata.com/support/faqs/data/distinct.html

Johannes 

owner-statalist@hsphsun2.harvard.edu schrieb am 18/09/2008 10:45:37:

> Let me ask my question again.
> 
> I have the variables year state cnum candidat.
> 
> Year state and candidate have the usual meaning.
> 
> cnum is the consituency within a state.
> 
> So in one year I may have 5 states and within that I may have 10
> constituencies and within those  I may have say 4 candidates each.
> 
> I want to compute the number of constituencies in each state.
> 
> I try to do this by : -
> 
> gen noofct=0
> 
> bysort year state cnum : count and now I want to store r(N) in noofct
> variable. So the noofct variable will have the same value in any one
> consituency. This is what I am not able to do.
> 
> Can someone tell me how to do this ?
> 
> Thank you,
> Ashim.
> 
> 
> 
> 
> 
> 
> On Thu, Sep 18, 2008 at 1:18 PM, Johannes Geyer <JGeyer@diw.de> wrote:
> > To me it is not clear what you try to achieve. It is easier to help if 
you
> > explain what variables you have and what you are trying to do using 
Stata,
> > in particular describe an error if it occurs.
> >
> > I assume you want to count the number of candidates in each state but 
I
> > have no idea what "cnum" and "cname" mean and what "count" is. Is 
"count"
> > a variable? Note that the syntax of the command count is different. 
And
> > remember that "(" ")" parentheses in a by-statement have an important
> > meaning: "The varlist1 (varlist2) syntax ... verifies that the data 
are
> > sorted by varlist1 varlist2 and then performs a  by as if only 
varlist1
> > were specified."
> >
> > Johannes
> >
> > owner-statalist@hsphsun2.harvard.edu schrieb am 18/09/2008 09:34:21:
> >
> >> 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