In addition to other replies, there is a -selectvars-
package on SSC:
----------------------- extract from help
-selectvars- produces a list of all possible n-tuples from a list of
variable names. That is, given a list of k variable names, it produces the
empty list; all possible distinct singletons (each individual variable
name); all possible distinct pairs; and so forth. Tuples are bound in " ".
As -selectvars- is intended for programming, the list is not displayed, but
left behind as a saved result.
Note that there is no checking of a possible error with even modest k:
that a full list of (at most 2^k) tuples can not be accommodated in a
macro.
------------------------
Note that -selectvars- long predates Mata. I would be interested to know
if it could be speeded up. Mata or not, I have always been queasy
about programs like this because I feared that someone would
engender a combinatorial explosion (a genuine term in the literature).
Nick
[email protected]
James Muller
> Does anybody know of a package that generates permutations and
> combinations? That is, the actual ordered/unordered sets of
> combinations
> or permutations of elements from a set.
>
> I wrote a little package that does this for the set {1,2,...,n} a few
> months ago, and just want to check that there isn't already something
> equivalent out there.
>
> Also, does anybody have a wishlist of combinatoric operations
> that they would like to see in Stata, other than for the generation of
> the above sequences?
*
* 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/