Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop for multiple regressions with different dependent variables

    Dear all,

    I have multiple different dependent variables (six in total but this can become more) and I would like to create a loop that runs the regression for each dependent variable and then stores the results for each regression. After this, I'd like to present the results for the different models in a nice output table.
    It seems like something fairly simple but I just can't find how to do this. I was thinking in the line of:

    local i = 1
    foreach var of global y_vars {
    probit `var' i.treatment $var_demo $var_location
    estimates store m`i'
    local `i' = `i' + 1
    }
    log using "Example.smcl", append
    estout m1 m2 m3 m4 m5 m6, keep(*.treatment) cells(b(star fmt(3)) se(fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) stardetach ///
    legend label varlabel (_cons Constant) varwidth(15)
    log close

    But this clearly doesn't work because it only stores the estimates of the first dependent variable.
    Does someone have advice for me? Thanks!


  • #2
    Assuming you have defined your y_vars and $var_demo $var_location beforehand, change the last line within the loop to:

    Code:
    local ++i
    instead
    Code:
    local `i' = `i' + 1
    Roman

    Comment


    • #3
      Thank you, Roman! Now it works perfectly.

      Comment

      Working...
      X