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/