Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Combinations of 3


From   Kari Hexem <khexem@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Combinations of 3
Date   Sun, 19 Dec 2010 19:29:00 -0500

Thank you!  It worked!!

On Sun, Dec 19, 2010 at 7:16 PM, Tirthankar Chakravarty
<tirthankar.chakravarty@gmail.com> wrote:
> ******************************************
> // generate some data
> clear
> set obs 100
> g v = runiform()
> forv i=1/6{
>        g n`i' = runiform()
> }
> // sum variables
> forv i=1/5 {
>        forv j = `=`i'+1'/6 {
>                g v_n`i'_n`j' = v + n`i' + n`j'
>        }
> }
> su
> ******************************************
>
> T
> On Sun, Dec 19, 2010 at 4:03 PM, Kari Hexem <khexem@gmail.com> wrote:
>> 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/
>>
>
>
>
> --
> To every ω-consistent recursive class κ of formulae there correspond
> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
> belongs to Flg(κ) (where v is the free variable of r).
>
> *
> *   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/
>

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index