Statalist The Stata Listserver

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

st: powerset of a list

From   "Carole J. Wilson" <[email protected]>
To   [email protected]
Subject   st: powerset of a list
Date   Fri, 22 Sep 2006 17:43:21 -0500

Does anyone know of stata code to generate a powerset of a list in stata?

I will be using the elements of the subsets in different calls to a routine.
So, given {1, 2, 3}, I would like stata to return: {1}, {2}, {3}, {1,
2}, {1, 3}, {2, 3}, {1, 2, 3} (return of the null set is optional)
possibly returning the subsets in a variable.
In a simplified version of my code, I will be generating variables
based on these subsets and their complements e.g.:

I'll also be generating variables from subsets that contain specific elements:
r1=x1*(x1+x2)*(x1+x3)*(x1+x2+x3)  <==subsets that contain 1
r2=x2*(x1+x2)*(x2+x3)*(x1+x2+x3)  <==subsets that contain 2
r3=x3*(x1+x3)*(x2+x3)*(x1+x2+x3)  <==subsets that contain 3

My goal, of course, is to generalize these operations to n elements of a list

Thank you,
Carole Wilson
*   For searches and help try:

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