title: R Loop Regressions
body: <pre><code>data=mtcars
  data$group = rep(seq(from=1, to=4, by=1), 8)
  
  
  model1 &lt;- glm(vs ~ mpg + cyl + disp + hp, data = subset(data, group == 1), family = "binomial")
  model2 &lt;- glm(vs ~ mpg + cyl + disp + hp, data = subset(data, group == 2), family = "binomial")
  model3 &lt;- glm(vs ~ mpg + cyl + disp + hp, data = subset(data, group == 3), family = "binomial")
  model4 &lt;- glm(vs ~ mpg + cyl + disp + hp, data = subset(data, group == 4), family = "binomial")
  
  model5 &lt;- glm(am ~ mpg + cyl + disp + hp, data = subset(data, group == 1), family = "binomial")
  model6 &lt;- glm(am ~ mpg + cyl + disp + hp, data = subset(data, group == 2), family = "binomial")
  model7 &lt;- glm(am ~ mpg + cyl + disp + hp, data = subset(data, group == 3), family = "binomial")
  model8 &lt;- glm(am ~ mpg + cyl + disp + hp, data = subset(data, group == 4), family = "binomial")
  </code></pre>
  
  <p>Say you want to estimate a bunch of stratified models that are identical in every way except the stratified group (models 1-4) and also that you want to repeat this series of models for different outcomes (models 5-8). </p>
  
  <p>That is what I have for the code above. However, is there a more efficient way to run this in terms of it not taking up as many lines of code? For example to specify the covariates, outcomes, and groups, and then loop over them?</p>