[R] foreach loop, stata equivalent

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Feb 19 14:02:02 CET 2013



On 18.02.2013 13:39, Jamora, Nelissa wrote:
> Hi! I'm a recent convert from Stata, so forgive my ignorance.
>
>
>
> In Stata, I can write foreach loops (example below)
>
>
>
> foreach var of varlist p1-p14 {
>
> foreach y of varlist p15-p269 {
>
>    reg `var' `y'
>
> }
>
> }
>
>
>
> It's looping p1-p15, p1-p16...., p1-p269, p2-p15, p2-p16,... p2-p269,...
> variable pairs.
>
>
>
> How can I write something similar in R?


help("for")

Uwe Ligges



> I 'tried' understanding the package.foreach but can't get it to work.
>
>
>
> Thanks for any help
>
> Nelissa
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list