title: Running lagged regressions with lapply and two arguments
body: <p>I am running multiple univariate regressions, like in this reproducible example:</p>
  
  <pre><code>require(dynlm)
  data(USeconomic)
  US&lt;-USeconomic
  vars&lt;-colnames(US)[-2]
  a&lt;-lapply(colnames(US),function(x) dynlm(log(GNP)~get(x),data=US))
  </code></pre>
  
  <p><code>a</code> contains a list of 3 univariate regressions. Assume now I´d like to run the same regressions with 3 lags: <code>l&lt;-c(0,1,4)</code> where 0 is of course the case I already got. Is there a way to use the vector <code>l</code>directly, like</p>
  
  <pre><code># this did not work for me, I obtain multivariate regressions including all lags at once
  lapply(colnames(US),function(x) dynlm(log(GNP)~L(get(x),l),data=US),l=l)
  </code></pre>
  
  <p>After this did not work I tried another approach and added to following vector:</p>
  
  <pre><code>lagged_vars &lt;- paste("L(",rep(vars,each=3),",",l,")",sep="")
  </code></pre>
  
  <p>to get: </p>
  
  <pre><code>[1] "L(log(M1),0)" "L(log(M1),1)" "L(log(M1),4)" "L(rs,0)"      "L(rs,1)"     
  [6] "L(rs,4)"      "L(rl,0)"      "L(rl,1)"      "L(rl,4)"
  </code></pre>
  
  <p>Unfortunately, I can't run it with the new character vector, get() does not help. I can't understand why cause it works with <code>vars</code> but not <code>lagged_vars</code> which are both character vectors. </p>
  
  <p>Note, that the <code>L()</code> syntax comes from the dynlm package. 
  Side question: If I just print a the coefficients from the regression result remain labelled get(x) – how can I change that?</p>
  
  <p>An i,j loop could be possible solution but I´d rather use lapply or something out of this family...</p>
  
  <p>EDIT:
  <code>as.formula</code> does not work together with <code>L()</code> from <code>dynlm</code>. I get the this error message:</p>
  
  <p>Error in merge.zoo(log(GNP), L(log(M1), 0), retclass = "list", all = FALSE) : 
    could not find function "L"</p>
  
  <p>EDIT:
  found an <a href="http://r.789695.n4.nabble.com/dynlm-question-How-to-predefine-formula-for-call-to-dynlm-formula-call-td885792.html" rel="nofollow">interesting post bei Achim Zeileis</a> referring to this problem.</p>