Announcement

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

  • Loop over different dependent and independent variables

    [I am using STATA 15.0] I am trying to run ANCOVA regression and store the results using eststo and esttab. I have three different dependent variables (Xb Yb Zb), three different independent variables (Xf1 Yf1 Zf1), and a set of control variables (A B C D). My 1st regression specification is: eststo: reg Xb Xf1 A B C D, cluster (id). My 2nd regression specification is: eststo: reg Yb Yf1 A B C D, cluster (id), and the 3rd one is: eststo: reg Zb Zf1 A B C D, cluster (id). I was trying to run 3 regressions using loop; however, I failed. Can anyone please help me with how should I write the loop command? Thank you in advance.

  • #2
    In your case writing a loop is counter productive, because it is easier and faster to do this without a loop.

    If for educational purposes you want to learn how to do this, read this FAQ here:

    https://www.stata.com/support/faqs/p...arallel-lists/

    Comment


    • #3
      Thank you, Mr Kolev for the link. I have written the command in the following way and it worked. I am sharing the codes here because there might be someone like me who need to learn it.

      local dv Xb Yb Zb
      local indv Xf1 Yf1 Zf1
      local cv A B C D

      forvalues i=1/3 {
      local DV: word `i of `dv'
      local InV: word `i' of `indv'
      eststo: reg `DV' `InV' `cv', cluster (id)
      }

      Note: forvalues i=1/3 * This 3 represents the number of the dependent variables (* I can change it to any number according to the number of the dependent variables). One thing that is important here- I have an equal number of dependent and independent variables and I regressed the first dependent variable on the first independent variable and so on. However, if I don't have an equal number of dependent and independent variables then the regression results might not be appropriate for some dependent variables. So, it is crucial to look at the results carefully.

      Comment


      • #4
        .
        Last edited by Hasib Reza; 21 Nov 2022, 02:43.

        Comment

        Working...
        X