I have a nested loop with 60 dimensions, i.e. I nest 60 loops into each other. In Stata the MWE would look like the following:
forvalues i = 1/60 {
forvalues j = 1/60 {
forvalues k = 1/60 {
forvalues l = 1/60 {
... imagine the 56 remaining loops here
}
}
}
}
The equivalent in R is:
for(i in 1:60) {
for(j in 1:60) {
for(k in 1:60) {
for(l in 1:60) {
... imagine the 56 remaining loops here
}
}
}
}
The objective here is to avoid typing all 60 levels into my code and create a loop for the loop structure itself instead. This question appears so trivial. But for some reason I am struggling to come up with a solution.
Thank you for any suggestions.
Additional Information:
I have a dataset with 60 explanatory variables in it and would like to run regressions with every possible combination of these variables. More specifically I run univariate regressions of the dependent variable on all 60 explanatory variables separately and calculate certain criteria. Then I add a second regressor to the estimation equation and calculate criteria again. I.e. reg DependentVar ExplVar1 ExplVar2
, reg DependentVar ExplVar1 ExplVar3
, ..., reg DependentVar ExplVar60 ExplVar59
. Dependent on the calculated criteria a branch of that regression tree is either advanced or terminated. E.g. the first branch reg DependentVar ExplVar1 ExplVar2
either continues to grow as reg DependentVar ExplVar1 ExplVar2 ExplVar3
, reg DependentVar ExplVar1 ExplVar2 ExplVar4
etc. or terminated as reg DependentVar ExplVar1 ExplVar2
. Branches that contain an explanatory factor more than once are also cut - such as reg DependentVar ExplVar1 ExplVar1
or reg DependentVar ExplVar1 ExplVar2 ExplVar1
. Overall, I hence design a model selection approach. I am aware of already existant model selection commands, but need one that is customized to specific properties of the given dataset.