Announcement

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

  • How to keep quotation marks in syntax when giving a option two string arguments

    Hello, I am making a lot of graphs, and to keep things neater I would like to make a program. I am unable to extract the exact code, but I am giving an example below.

    So I want to plot x against y, and have a texbox above the y-axis as a axis title, simplified code is:

    Code:
    program income_graph
    syntax varlist(min=2) [if] [, y_title(str)] graph twoway line `1' `2' `if', text(310000 -5 `y_title')
    end
    When I then do

    Code:
    income_graph fam_inc t, y_title("Family Income" "In Thousands")
    I then get the error "In range not allowed r(101)"

    If i replace the code with:

    Code:
    program income_graph
    syntax varlist(min=2) [if] [, y_title(str)]
    graph twoway line `1' `2' `if', text(310000 -5 "`y_title'")
    end
    And again run
    Code:
    income_graph fam_inc t, y_title("Family Income" "In Thousands")
    , it will now give me a figure, but the title is not in two lines, but in one. So y_title now gives: "Family Income In Thousands" and not "Family Income" "In Thousands"

    Does anyone have any suggestions on how I can keep the two arguments, so that I can get the y-axis title on two separate lines?
    I have tried to use the -tokenize- code, but already then I can only give it the argument "Family Income In Thousands" , so the middle quotation marks are removed from the beginning, so I suspect I need to modify the -syntax- code, but I havent found any solutions.

  • #2
    The syntax may need to be

    Code:
    syntax varlist(min=2) [if] [, y_title(str asis)
    and you're likely to need make much more use of compound double quotes:


    Code:
    `" "'

    Comment


    • #3
      Originally posted by Nick Cox View Post
      The syntax may need to be

      Code:
      syntax varlist(min=2) [if] [, y_title(str asis)
      and you're likely to need make much more use of compound double quotes:


      Code:
      `" "'
      Excellent, asis does it. Now my program works as intended. I am unsure about the double quotes, for now I have managed without them. But I must confess that when it comes to Stata I am incredibly confused when it comes to locals, calling macroes and quotation marks (and double(/tripple?) quotation marks, especially the
      Code:
      `"` '"'
      But now I have the code below, which works as intended (or asis if you´d like).

      Code:
       program income_graph
      syntax varlist(min=2) [if] [, y_title(str asis)]
      graph twoway line `1' `2' `if', text(310000 -5 `y_title')
      end
      Which gives me exactly what I want when i give it

      Code:
       income_graph fam_inc t, y_title("Family Income" "In Thousands")

      Comment


      • #4
        Good!

        Comment

        Working...
        X