Statalist


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

RE: st: RE: Re:distribution code


From   "Steichen, Thomas J." <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: Re:distribution code
Date   Wed, 16 Jan 2008 10:00:43 -0500

Nick Cox writes:
This ia good progress! How would you generalise your match-ups
AB CH DG EF to arbitrary even numbers of teams?

How about this?

Tom

* --------------------------------------
clear

* set # teams before running
local teams 16

local obs = `teams' - 1
set obs `obs'
gen round = _n

gen T1=1
foreach t of numlist 2/`teams' {
  gen T`t' = `t'-1 + round
}

foreach t of numlist 2/`teams' {
  qui replace T`t' = T`t'-`obs' if T`t'>`teams'
}

local match = `teams'/2
egen field1 = concat(T1 T2), punct("_")
foreach m of numlist 2/`match' {
  local l = `m' + 1
  local k = `teams' + 2 - `m'
  egen field`m' = concat(T`l' T`k'), punct("_")
}

l field*, sep(2)

*confirm no repeats
preserve
drop T*
reshape long field, i(round) j(f)
qui tab field
return list
if r(N) == r(r) {
  di "OK, each matchup occurs exactly once"
}
else {
  di "ERROR, some matchups are duplicated"
}
restore
* --------------------------------------

-----------------------------------------
CONFIDENTIALITY NOTE: This e-mail message, including any
attachment(s), contains information that may be confidential,
protected by the attorney-client or other legal privileges, and/or
proprietary non-public information. If you are not an intended
recipient of this message or an authorized assistant to an intended
recipient, please notify the sender by replying to this message and
then delete it from your system. Use, dissemination, distribution,
or reproduction of this message and/or any of its attachments (if
any) by unintended recipients is not authorized and may be
unlawful.   

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