Announcement

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

  • update value of local

    Hi,

    Suppose, you have a local, which depends on a second local. However, when the first local is defined, the second local is not defined yet. Is it possible to update the first local as soon as the second local is defined (so that it takes the new value into account).

    Example
    Code:
    local test test`ev'
    local ev = 100
    di "`test'"
    The local should be "test100".

    Thanks a lot!

  • #2
    Your understanding of how macros work is incorrect. In the first line, the macro referencve `ev' is replaced by its current value at that time.
    Code:
    . local test test`ev'
    
    . macro list _test
    _test:          test
    You need to precede the backquote with a backslash to prevent it from triggering macro expansion at that time.
    Code:
    . local test test\`ev'
    
    . macro list _test
    _test:          test`ev'
    
    . local ev = 100
    
    . macro list _test
    _test:          test`ev'
    
    . display "`test'"
    test100

    Comment


    • #3
      But why would you ever want to do this?

      Comment


      • #4
        Dear William,

        Thank you so much. I didn't know that \ prevents triggering macro expansions. This is very helpful!

        Nick, perhaps out of better programming skills. After regress, I need to select some coefficients in a very specific way to use them with the lincom command. Some coefficients need to be fixed, other move within a double loop. I figured that using macro expansions at different times can be a suitable solution for what I want to do.

        Thanks again!

        Comment


        • #5
          There is no need to define or evaluate anything until you need it.

          Comment

          Working...
          X