 Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: RE: creating loops using combinations of variables

 From Zeynep Ozkok To statalist@hsphsun2.harvard.edu Subject Re: st: RE: creating loops using combinations of variables Date Thu, 16 Feb 2012 12:59:42 +0100

```Hi,

Thank you very much for your comment Nick.

Let me try to clarify the issue a bit by taking three variables as you
suggested.

On Thu, Feb 16, 2012 at 11:41 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> "All possible combinations" would usually mean, for 27 variables, 27 ways of selecting just one, comb(27, 2) = 351 ways of selecting two, ..., up to comb(27, 27) = 1 way of selecting them all. In total that means 2^27 - 1 ~ 10^8 combinations. That is, precisely, 134,217,727 combinations.
>
> My suggestion is to set aside the fact that you have 27 variables. Show us exactly what you would do with just 3 variables, say.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Zeynep Ozkok
>
> I have a question on how to create loops for combinations of different
> variables. I have 27 variables that I would like to put in two different
> indices.
>
> The indices can be constructed in two steps:
>
> Lex1=sum(of different variables out of 27)   this variable should be able
> to take on 1 to 27 variables, so it should allow for all possible
> combinations. It could be equal to only 1 variable, or it could be equal to
> the sum of different variables
>
> Index1 = ln (1+lex1)  this index is then dependent on what values lex1
> takes on
>
> Similarly
>
> Lex2 = sum (of all the variables that are not accounted in lex1) again this
> could take on one variable, or more than one depending on the structure of
> lex1.
>
> Index2 = ln(1+lex2) this index is once again dependent on what values lex2
> takes on, which is dependent on the values that lex1 takes on.
>
> Then these two indices will simultaneously be used in fixed effects
> regressions as follows:
>
> Y_i,s,t= alpha_i +alpha_s +alpha_t +beta*(index1)_i,t +lamda* (index2)_i,t
> + error_i,s,t
>
> The loop must go on until all possibilities/ combinations are completed. I
> need to check the results of the beta and lamda coefficients and their
> corresponding rsquares for each regression. Since there are numerous
> possibilities in constructing each index I need to create a loop. However I
> don't even know how to start out a loop that depends on combinations of
> variables. Could you possibly help me out in writing and solving this
> problem?
>
>
> *
> *   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/
```