Statalist


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

st: RE: Re:distribution code


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re:distribution code
Date   Tue, 15 Jan 2008 18:35:43 -0000

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

input a b

1 2

1 3

1 4

1 5

1 6

1 7

1 8

2 3

2 4

2 5

2 6

2 7

2 8

3 4

3 5

3 6

3 7

3 8

4 5

4 6

4 7

4 8

5 6

5 7

5 8

6 7

6 8

7 8

end

save a1,replace

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

I have written the following code but  a loop of two million could do
less
than half  of the job ..... ..

drop _all

set more off

set obs 1120

gen a = .

gen b = .

gen n = .

local i = 1

while `i'<= 16 {

local e = 1

while `e'<= 16 {

local n = [`i'-1]* 16 + `e'

replace a = `i' in `n'

replace b = `e' in `n'

replace n = `n' in `n'

local e = `e'+1

}

local i = `i'+1

}

drop if a>=b

replace n = _n

sort n

save a1,replace

local i = 1

while `i'<= 2000000 {

use a1,clear

di in yellow " " _N " " `i'

sample 8,count

save a2,replace

keep a

gen n = _n

sort n

save a3,replace

use a2,clear

keep b

rename b a

gen n = _n+8

sort n

merge n using a3

drop _merge

sort a

drop if a[_n]==a[_n-1]

if _N==16 {

use a2,clear

save ada`i',replace

sort n

merge n using a1

drop if _merge==3

drop _merge

sort n

save a1,replace

if _N==8 {

save adalast

}

if _N==8 {

exit

}

}

local i = `i'+1

}

dir

If anyone can tell me of a smarter code I would appreciate it greatly
,for I
have been banging my head at this for the past two weeks.

I thank you in advance ,

Victor M. Zammit

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