Thank you for the clear statement of your problem. It reassured me that the approach I was considering would meet your needs.
The application of modular arithmetic allows for very simple code - certainly nothing requiring authorship credit!
The application of modular arithmetic allows for very simple code - certainly nothing requiring authorship credit!
Code:
// set parameters local K 9 // number of studies local N 3 // maximum number of events to add // do the work local N1 = `N'+1 local No = `N1'^`K' assert `No'<=2147483620 // largest possible long set obs `No' generate long count = _n-1 forvalues k = `K'(-1)1 { generate byte study`k' = mod(count,`N1'), after(count) quietly replace count = floor(count/`N1') } // consistency checking and cleanup assert count==0 drop count // display sample results list in 1/5 list in -5/l
Code:
. // display sample results . list in 1/5 +--------------------------------------------------------------------------------+ | study1 study2 study3 study4 study5 study6 study7 study8 study9 | |--------------------------------------------------------------------------------| 1. | 0 0 0 0 0 0 0 0 0 | 2. | 0 0 0 0 0 0 0 0 1 | 3. | 0 0 0 0 0 0 0 0 2 | 4. | 0 0 0 0 0 0 0 0 3 | 5. | 0 0 0 0 0 0 0 1 0 | +--------------------------------------------------------------------------------+ . list in -5/l +--------------------------------------------------------------------------------+ | study1 study2 study3 study4 study5 study6 study7 study8 study9 | |--------------------------------------------------------------------------------| 262140. | 3 3 3 3 3 3 3 2 3 | 262141. | 3 3 3 3 3 3 3 3 0 | 262142. | 3 3 3 3 3 3 3 3 1 | 262143. | 3 3 3 3 3 3 3 3 2 | 262144. | 3 3 3 3 3 3 3 3 3 | +--------------------------------------------------------------------------------+
Comment