Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Kari Hexem <khexem@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Combinations of 3 |
Date | Sun, 19 Dec 2010 19:03:26 -0500 |
Hi, I would like to sum the numbers of variable v with 6 other variables: n1, n2, n3, n4, n5, n6, in combinations of 3. So the results would be the sums of the following variables, identified using 15 combinations (6 choose 2), or, to spell it out, the sums of each of these following possibilities: v-n1-n2 v-n1-n3 v-n1-n4 v-n1-n5 v-n1-n6 v-n2-n3 v-n2-n4 v-n2-n5 v-n2-n6 v-n3-n4 v-n3-n5 v-n3-n6 v-n4-n5 v-n4-n6 v-n5-n6 I can get the sum of the first two of the 3 variables by using the following code: forvalues i=1(1)6 { gen sum`i' = v + n`i' } but I can't figure out how to add in the 3d variable, which can't be a repeat of the 2nd variable (ie. v-n1-n1 is not allowed). Thoughts? I feel like it should have something to do with nested loops, or the -selectvars- command, but I am totally stuck. Any help would be greatly appreciated. Thanks, Kari * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/