Announcement

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

  • How to obtain the following through loops

    Dear all,

    Given the following loop:
    Code:
        foreach y in first_outcome second_outcome {
            eststo `y': reg `y' x1 x2 x3
        }
    What I want is to shorten names of storing estimates. For example, I want to have m1 and m2 instead of first_outcome and second_outcome. I have seen something like this but not I was unable to find that thread. Thank you.

  • #2
    Code:
     
     local c = 1 foreach y in first_outcome second_outcome {    eststo m`c': reg `y' x1 x2 x3    local c = `c' + 1 }

    Comment


    • #3
      Code:
       
       foreach y in m1 m2 {

      Comment


      • #4
        Originally posted by George Ford View Post
        Code:
        local c = 1 foreach y in first_outcome second_outcome { eststo m`c': reg `y' x1 x2 x3 local c = `c' + 1 }
        Thank you so much for the quick reply. The code in #2 is exactly what I want. Just a follow-up question, now instead of having m1 and m2, would it be possible to have A and B? Thank you.

        Comment


        • #5
          Code:
          sysuse auto, clear
          local c = 1  
          foreach y in weight trunk {
              local mod : word `c' of `c(ALPHA)'    
              eststo `mod': reg `y' mpg i.rep78    
              local c = `c' + 1  
          }

          Comment


          • #6
            If you have two y, then I wouldn't bother with the loop.

            Comment


            • #7
              Originally posted by George Ford View Post
              Code:
              sysuse auto, clear
              local c = 1
              foreach y in weight trunk {
              local mod : word `c' of `c(ALPHA)'
              eststo `mod': reg `y' mpg i.rep78
              local c = `c' + 1
              }
              Thank you so much for the help. Indeed, I have more than two y.

              Comment


              • #8
                #3 is nonsense here, but journals.sagepub.com/doi/pdf/10.1177/1536867X211063415 includes a review of technique for loops in parallel.

                Comment

                Working...
                X