title: Looping through covariates in regression using R
body: <p>I'm trying to run 96 regressions and save the results as 96 different objects. To complicate things, I want the subscript on one of the covariates in the model to also change 96 times. I've almost solved the problem but I've unfortunately hit a wall. The code so far is,</p>
  
  <pre><code>for(i in 1:96){
  
    assign(paste("z.out", i,sep=""), lm(rMonExp_EGM~ TE_i + Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
    Month10+Month11+Month12+Yrs_minus_2004 + 
    as.factor(LGA),data=Pokies))
  
  }
  </code></pre>
  
  <p>This works on the object creation side (e.g. I have z.out1 - z.out96) but I can't seem to get the subscript on the covariate to change as well. </p>
  
  <p>I have 96 variables called TE_1, TE_2 ... TE_96 in the dataset. As such, the subscript on TE_, the "i" needs to change to correspond to each of the objects I create. That is, z.out1 should hold the results from this model: </p>
  
  <pre><code>z.out1 &lt;- lm(rMonExp_EGM~ TE_1 + Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
    Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies)
  </code></pre>
  
  <p>And z.out96 should be: </p>
  
  <pre><code>z.out96 &lt;- lm(rMonExp_EGM~ TE_96+ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
    Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies)
  </code></pre>
  
  <p>Hopefully this makes sense. I'm grateful for any tips/advice. </p>