Search code examples
loopsfor-loopforeachstata

Stata Loop for lagged variable


i want to regress two variables r and in. But i want to test multiple lags for the variable in and check which lag delivers the best fit for Rsquared.

I want to test -3,-2,-1,0,1,2,3

regress r l.in 
regress r l2.in
regress r l3.in

 (.....)

Is it possible to do this using a loop ?


Solution

  • forval k = 1/7 { 
        regress r l`k'.in
    }