Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Help Creating a Count Variable - correction


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Help Creating a Count Variable - correction
Date   Thu, 14 Jul 2005 17:34:01 +0100

In addition, the -egen- function -nvals()- in the -egenmore-
package on SSC cans this logic as a named function. 

Nick 
[email protected] 

Jonathan Beck
 
> sorry. use egen!
> 
> . bysort district party: gen partycount=_n==1
> . bysort district: egen noParties=sum(partycount)
> . drop partycount
> 
> there is most probably also a one-liner, but i hope this 
> works as well.
 
[email protected] wrote:

> I have a coding question.  I have individual-level 
> data (candidates)
> > nested in aggregate-level units (electoral districts).  I 
> am attempting to
> > create a variable that indicates that number of different 
> parties (not the
> > number of candidates, but the number of political parties 
> present) present in
> > an electoral district.
> > 
> > For example in District A: I have five candidates from 3 
> different parties.
> > 
> > I need advice on how to generate this variable.  I have 
> tried the egen var=
> > count() method after sorting on the district.  This does 
> not work. 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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