Skip to content
Prev 317806 / 398513 Next

foreach loop, stata equivalent

Le lundi 18 f?vrier 2013 ? 13:48 +0100, Jamora, Nelissa a ?crit :
You do not need package foreach, which is intended at a completely
different problem.

R does not really have the syntactic equivalent of "varlist", but you
can easily do something like:
for(var in paste0("p", 1:14)) {
    for(y in paste0("p", 15:269))
        lm(yourData[[var]] ~ yourData[[y]])
}

provided that yourData is the data frame in which the p* variables are
stored.

There are probably more direct ways of doing the same thing and storing
the resulting lm objects in a list, but you did not state what you
intend to do with this enormous set of regressions...


Regards