This ia good progress! How would you generalise your match-ups
AB CH DG EF to arbitrary even numbers of teams?
Nick
[email protected]
Elizabeth Rainwater
I have written a bit of code that I think might do the trick. I'm sure
it could be condensed and written in to a loop, but I wanted it to be as
clear as possible. I think it could be extended for more teams fairly
easily.
*---------begin code--------*
clear
set obs 7
input round
1
2
3
4
5
6
7
end
* gen initial values for 8 teams
gen A = 1
gen B = 1 + round
gen C = 2 + round
gen D = 3 + round
gen E = 4 + round
gen F = 5 + round
gen G = 6 + round
gen H = 7 + round
* fix so 9->2, 10->3, etc
replace B = B-7 if B>8
replace C = C-7 if C>8
replace D = D-7 if D>8
replace E = E-7 if E>8
replace F = F-7 if F>8
replace G = G-7 if G>8
replace H = H-7 if H>8
* for the brackets: the matchups are always AB CH DG EF
egen field1 = concat(A B), punct("_")
egen field2 = concat(C H), punct("_")
egen field3 = concat(D G), punct("_")
egen field4 = concat(E F), punct("_")
*--------end code--------*
The above gives me the following matchups:
. cl field*
field1 field2 field3 field4
1. 1_2 3_8 4_7 5_6
2. 1_3 4_2 5_8 6_7
3. 1_4 5_3 6_2 7_8
4. 1_5 6_4 7_3 8_2
5. 1_6 7_5 8_4 2_3
6. 1_7 8_6 2_5 3_4
7. 1_8 2_7 3_6 4_5
Does anyone see anything wrong with this approach?
-Elizabeth
Nick Cox wrote:
> Victor has posted three versions of this problem, without
> a flicker of public response that I can recall.
>
> The interpretation that I find easiest of his problem is
>
> Eight teams 1-8.
> Each team plays every other team just once.
>
> Evidently there are 8 * 7 / 2 matches and 7 rounds of matches. I
notice
> no distinction between "home" and "away".
>
> I had a few goes at doing this in Stata, but in each case only managed
> code for an easier half of the problem. The best data structure for
this
> is to me far from obvious. Victor wants each match to be an
observation,
> but I wouldn't be at all surprised if you were better off with each
> round as an observation. Thus you are working with various shuffles of
> "12345678" divided into pairs, with the understanding that "12" and
"21"
> are not distinct.
>
> In case it is also of interest, I offer here a solution obtained "by
> hand".
> 12, for example, means "1 and 2 play".
>
> 12 34 56 78
> 13 24 57 68
> 14 25 38 67
> 15 26 37 48
> 16 23 47 58
> 17 28 36 45
> 18 27 35 46
>
> This took much less time than my various failed programming efforts.
>
> Of course, if the real problem has say 16 or 64 teams, and this one is
> just a toy, then this is no use whatsoever.
>
> Nick
> [email protected]
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Victor M.
> Zammit
> Sent: 14 January 2008 22:01
> To: [email protected]
> Subject: st: Re:distribution code
>
> Dear Listers,
>
> I have the following dataset
> <snip>
>
> and I need to find the code capable of distributing it in seven groups
> ,of
> four observations (pairs of numbers) each ,such that each group would
> have
> eight numbers and no group may contain any repeating number
>
> and no pair of numbers may be repetitive within the seven groups.For
> example
> :
>
> 1 2,3 4,5 6,7 8
>
> 1 3,2 6,3 7,4 8
>
> .........................
>
> .........................
>
> .........................
>
> ........................
>
> 1 8,2 7,3 6,4 5
>
*
* 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/