Statalist


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

st: Re:distribution code


From   "Victor M. Zammit" <[email protected]>
To   <[email protected]>
Subject   st: Re:distribution code
Date   Mon, 14 Jan 2008 23:00:35 +0100

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/



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