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

From |
Antoine Terracol <[email protected]> |

To |
[email protected] |

Subject |
Re: st: RE: Programming Problem |

Date |
Fri, 19 Jul 2002 18:37:02 +0200 |

Guido,

Here's a quick-and-dirty solution that seems to work. it uses local macros and scalars, so it's pretty fast. I guess you'll find a way to pass the number of votes from the dataset to scalars.

however, the sequence of dividers here is "1,2,3,4,...,m"

Hope this helps,

Antoine.

----------------------------------------------------------

clear

/*fill in the number of seats and the number of parties*/

local totalseat=6

local nbparties=4

/*fill in the number of votes*/

scalar nbvp1=41000

scalar nbvp2=29000

scalar nbvp3=17000

scalar nbvp4=13000

local i=1

while `i'<=`nbparties' {

local nbs`i'=0

scalar nbv`i'=scalar(nbvp`i') /*scalars to be divided during the loop*/

local i=`i'+1

}

local string "scalar(nbv1)"

local i=2

while `i'<=`nbparties' {

local string "`string', scalar(nbv`i')" /*builds the list of votes to be compared*/

local i=`i'+1

}

local i=1

while `i'<=`totalseat' {

local j=1

local done=0

while `j'<=`nbparties' {

if scalar(nbv`j')==max(`string') & `done'==0 {

local nbs`j'=`nbs`j''+1 /*increment the number of seats*/

local done=1

scalar nbv`j'=scalar(nbvp`j')/`nbs`j'' /*divide total votes by number of seats+1*/

}

local j=`j'+1

}

local i=`i'+1

}

local i=1

while `i'<=`nbparties' {

di "Party `i' gets `nbs`i'' seats"

local i=`i'+1

}

------------------------------------------------------

Guido Tiemann wrote:

At 11:17 19.07.2002 -0400, you wrote:I'm not entirely clear on the algorithm here. Is it: 1. Assign a seat to current highest vote getter. 2. Divide that party's votes by (1+number of seats they've been awarded so far). 3. Return to step 1, until all seats are assigned.

Yep, you are quite right, Nick. Sorry, if I did not clarify this point. There is only one qualification, I would like to add to my former posting: The sequence of divisors might also be a different one, for instance, 1 - 3 - 5 (or even 1.4 - 3 - 5) for the method of (modified) Sainte Lague. In addition, I would like to preserve the initial votes that will be needed for further calculations, and the data set is rather huge (about 200 meg). As a consequence, my "brutal" slope + dummy approach took really long ...

Guido Tiemann

*

* 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/

**References**:**Re: st: RE: Programming Problem***From:*Guido Tiemann <[email protected]>

- Prev by Date:
**RE: st: RE: Programming Problem** - Next by Date:
**st: standardizing on [0,1]** - Previous by thread:
**Re: st: RE: Programming Problem** - Next by thread:
**RE: st: RE: Programming Problem** - Index(es):

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