Announcement

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

  • How to escape quote symbol inside a global macro

    I'd like to define a global macro to use for graphing purposes, so I'd like the macro to be the full text for the option: xtitle("")

    How can I define this global macro? I have read about escaping quotes, but I tried the following which do not work

    global test1 "xtitle(" "`""""'" ")"

    global test2 "`"xtitle("")"'"

    Thanks for reading.

  • #2
    You should look over the output of help quotes paying particular attention to the material on "compound double quotes". Here is an example.
    Code:
    . local gnxl `"xtitle("")"'
    
    . macro list _gnxl
    _gnxl:          xtitle("")
    
    . display "`gnxl'"
    xtitle()
    
    . display `"`gnxl'"'
    xtitle("")
    Let me add that your question would have been easier to read had you surrounded your commands in a CODE block, as I did above, and as is requested by the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. See especially sections 9-12 on how to best pose your question. For example, the following:

    [code]
    global test1 "xtitle(" "`""""'" ")"

    global test2 "`"xtitle("")"'"
    [/code]

    will be presented in the post as the following:
    Code:
    global test1 "xtitle(" "`""""'" ")"
    
    global test2 "`"xtitle("")"'"
    And having done that, I now can tell that your second answer is similar to mine. You said it didn't work, but did not describe how in what way it failed, so I refer you back to the FAQ, which in Section 12.1 offers the following advice.

    12.1 What to say about your commands and your problem

    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
    ...
    Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

    Comment


    • #3
      Thank you William, your example works perfectly. I will remember your other points as well.

      Comment

      Working...
      X