Announcement

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

  • Is there a way for a program to assign an ordinary local macro in the "parent" scope?

    Is there a way for a program to pass an ordinary local macro to the "parent" scope, or must I use a workaround like this?

    Code:
    program myprog, rclass
    return local rmyvar "foo"
    end
    
    ​myprog
    local myvar `r(rmyvar)'
    I call this program a bunch of times, and defining the locals over and over seems like a lot of duplication.

  • #2
    Yes. It's is c_local and explained in various places. e.g. http://www.stata.com/statalist/archi.../msg00385.html

    The usual arch comment is that you should use it only if you can explain how dangerous it can be as well as how useful.

    Comment


    • #3
      Bingo. Thanks.

      AFAICT, this is functionally no more dangerous than a global, but is dangerous insofar as it subverts the meaning (and therefore the expectation of the behavior) of "local". Does that sound correct?

      Comment


      • #4
        Spot on.

        Comment

        Working...
        X