Announcement

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

  • Macro loop to create labels for graph

    Hi I have a graph and I want to add text labels at various points

    I am trying to do this with a loop as the number of labels is large

    I was trying to create a "text" string to append to the end of my graph code using the function
    Code:
     text(y,x,string)
    Code:
    local row = 10
    local txt = ""
    
    forvalues n = 1/`row' {
        local txt = "`txt' text(0,`n',`""string_`n'""')"
    }
    
    dis "`txt'"
    this give me the output


    Code:
     text(0,1,` text(0,2,` text(0,3,` text(0,4,` text(0,5,` text(0,6,` text(0,7,` text(0,8,` text(0,9,` text(0,10,`
    but I need:
    Code:
     text(0,1,"string_1") text(0,2,"string_2") ...
    I assume this is due to the fact that I am doing something wrong with compound double quotes since I need quotes in the string part of the text() command.

    I cant figure out what is wrong.... any help would be appreciated.

    thanks!

    HP




  • #2
    Code:
    local row = 10
    local txt = ""
    
    forvalues n = 1/`row' {
        local txt = `"`txt' text(0,`n', "string_`n'")"'
    }
    
    dis `"`txt'"'

    Comment

    Working...
    X