Announcement

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

  • Looping over multiple couples of endogeneous variables and intrument


    I am writing a do file where I run 3 regressions: (i) the OLS, (ii) the IV first stage, (iii) the IV 2SLS.
    I have multiple variables to measure the endogenous explanatory variable; each of which have their own instrument.

    Is there a way I can loop the 3 regressions over each couple of endogenous variable-IV?
    I have 4 couples:
    1. Endogenous variable is X1, their instrument is IV1
    2. Endogenous variable is X2, their instrument is IV2
    3. Endogenous variable is X3, their instrument is IV3
    4. Endogenous variable is X4, their instrument is IV4

    My regressions are:

    Code:
           ** OLS
            reg `yvar' X1, robust
               
            ** IV First stage
            reg X1 IV1, robust
            
            ** 2SLS
            ivreg2 `yvar' (X1 = IV1), robust
    How can I loop the three equations over each of the 4 couples X(n)-IV(n)?

    Thanks,

  • #2
    Are the variables literally named X# and IV#?

    Code:
    forval i=1/4{
        ** OLS
            reg `yvar' X`i', robust
               
        ** IV First stage
            reg X`i' IV`i', robust
            
        ** 2SLS
            ivreg2 `yvar' (X`i' = IV`i'), robust
    }

    Comment


    • #3
      Thank you, Andrew!

      Comment

      Working...
      X