Announcement

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

  • Code Help: Modifying "forval" in a loop

    Hi,
    I ran a logit regression with 12 outcomes and would like to post the marginal results for each outcome in a table using a loop. I initially had it so that all the outcomes would be in the table but I would like to have only certain outcomes show (for ex, outcomes 1, 4, 6, and 8). Any help on how to get certain outcomes using a loop would be greatly appreciated.

    forval i=2/12{
    est restore model1
    quietly margins, at(homeown=(0 1) female=(0 1)) predict (outcome(`i')) post
    eststo Temp`i'
    etable, name(Table2) margins append
    collect export MyTable1.docx, as(docx) replace
    }

  • #2
    Code:
    forval i=2/12{
        est restore model1
        quietly margins, at(homeown=(0 1) female=(0 1)) predict (outcome(`i')) post
        eststo Temp`i'
        if inlist(`i', 1, 4, 6, 8) {
            etable, name(Table2) margins append
            collect export MyTable1.docx, as(docx) replace
        }
    }

    Comment


    • #3
      I think you could also just run the loop for the relevant values using foreach:

      Code:
      foreach i in 1 4 6 8 {
          est restore model1
          quietly margins, at(homeown=(0 1) female=(0 1)) predict (outcome(`i')) post
          eststo Temp`i'
          etable, name(Table2) margins append
          collect export MyTable1.docx, as(docx) replace
      }

      Comment


      • #4
        I tried out both methods and they both worked. Thank you!

        Comment

        Working...
        X