Announcement

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

  • Is there any way of using psacalc within a loop?

    I am running a fixed effects model using the -areg- command. Using Emily Oster's -psacalc-, I am looking to compute identified effect of a co-variate, say -variable1- with an rmax of 1.3 times the rmax of the controlled regression. I need to do this for multiple categories.

    Because of the large number of regressions required, I tried to put this in a loop. However, I am unable to run the -psacalc- command within the loop as the rmax() option does not accept anything other than scalars within the parenthesis. The code I used is:
    Code:
    foreach num of numlist 5 (1) 16 {
    areg y variable1 variable2 variable3 if variable4 == `num', absorb(variable5)
    psacalc beta variable1
    }
    Unfortunately, this code computes the identified effect using the default value of rmax, 1. What I am looking for is this:
    Code:
    psacalc beta variable1, rmax(display e(r2_a)*1.3)
    which gives the error option rmax() incorrectly specified

    Is there a way to put this in a loop?

    Any help would be appreciated. Thanks.

  • #2
    Calculating the desired value and saving the result in a local macro should do what you need.

    Code:
    foreach num of numlist 5 (1) 16 {
        areg y variable1 variable2 variable3 if variable4 == `num', absorb(variable5)
        local psmax = e(r2_a)*1.3
        psacalc beta variable1, rmax(`psmax')
    }
    For the experts reading this, I suspect saving the calculation in a scalar could also work, but I'm uncertain about whether passing a number as a scalar would get by the syntax checking in psacalc.

    Comment


    • #3
      Thank you for your reply, William. This was very helpful.

      Comment

      Working...
      X