Announcement

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

  • help with local macros

    Dear all,
    I would like to create several boxplots at once and combine them. i found the code below and it works very well. can some one help me understand the different sections. i understand the foreach command but i am confused about the rest mainly
    local names `names' graph`j'
    local j

    Thanks in advance


    Code:
    local j = 1
    local names
    foreach var of varlist A-X {
         graph box  `var', name(graph`j')
         local names `names' graph`j'
         local j
    }
    
    graph combine `names'
    Stata 15.1 Mac

  • #2
    Every time you create a new graph you add its name to the list of names so far. Once the loop is done you have a list of all the names to feed to graph combine.

    The first command blanks out the macro just in case it exists and contains irrelevant text.

    That said the line

    Code:
    local j
    looks wrong to me.

    It it would be better as

    Code:
    local ++j
    Last edited by Nick Cox; 30 Oct 2019, 03:52.

    Comment


    • #3
      yourare right Nick. it is ++j. but what does ++ mean?

      Comment


      • #4
        Code:
        help macro

        Comment


        • #5
          Code:
          help macro
          explains. The value of the local is bumped up (incremented by 1).

          Comment

          Working...
          X