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.:
s1=x1*(1-x2)*(1-x3)
s2=x2*(1-x1)*(1-x3)
s3=x3*(1-x1)*(1-x2)
s4=x1*x2*(1-x3)
s5=x1*x3*(1-x2)
s6=x2*x3*(1-x1)
s7=x1*x2*x3
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:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/