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   Jonathan Beck <[email protected]>
To   [email protected]
Subject   Re: st: Help Creating a Count Variable - correction
Date   Thu, 14 Jul 2005 14:18:12 +0200

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:
Hi all, 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. Any advice.

Thanks Gina Branton

*   For searches and help try:
*   For searches and help try:

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