-egen, sum()- is now undocumented, so for the clarity the second line
should refer to -total(tag)-, not -sum(tag)-.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 18 September 2008 12:14
To: [email protected]
Subject: RE: st: use of count.
I support Johannes' approach here. Note that
egen tag = tag(cnum), by(year state)
egen ncand = sum(tag), by(year state)
is nearly equivalent to his code.
Nick
[email protected]
Johannes Geyer
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
Ashim Kapoor
> 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 ?
*
* 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/