Announcement

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

  • displaying the contents of a macro

    Hi all: I am using "macro list" to display the contents of all the macros I have created (locals and globals). But what command to I use, or what option, to display the contents of just one macro, or just two? I have not been able to figure this out...

  • #2
    Hi,
    I normally use display, such as
    Code:
    di "`local'"
    di "$global"
    local and global are the individual macro names you are interested in.

    Comment


    • #3
      And, that seems to have done it. Thank you!

      Comment


      • #4
        While display is the common tool for displaying things flexibly, we should note for future readers that the macro list command will accept macro names and display just those macros.
        Code:
        . local mac1 "This is local macro mac1"
        
        . local mac2 "This is local macro mac2"
        
        . global mac3 "This is global macro mac3"
        
        . macro list mac3
        mac3:           This is global macro mac3
        
        . macro list _mac2
        _mac2:          This is local macro mac2
        Also, there are strange cases where display can mislead you and macro list is necessary to know exactly what the contents are.
        Code:
        . global odd \$strange
        
        . global strange even
        
        . * display $odd
        . macro list odd strange
        odd:            $strange
        strange:        even
        
        . display "$odd"
        even
        
        .

        Comment


        • #5
          Ah, that is very helpful, too. I did search the Stata command help files for something like this, but asked it to "help macro list", and it returned "help macrolists", which I did not notice the difference, and which was not what I was looking for. But if I just type "help macro", it does indeed show "macro list" as one option. Thank you.

          Comment

          Working...
          X