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

Re: st: Help Creating a Count Variable


From   Jonathan Beck <[email protected]>
To   [email protected]
Subject   Re: st: Help Creating a Count Variable
Date   Thu, 14 Jul 2005 14:15:49 +0200

. bysort district party: gen partycount=_n==1
. bysort district: gen noParties=sum(partycount)
. drop partycount

there is most probably also a one-liner, but i hope this works as well.
jonathan

[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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   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