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

RE: st: use of count.

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: use of count.
Date   Thu, 18 Sep 2008 12:19:11 +0100

-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. 

[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:

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:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index