Announcement

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

  • Commas in strings for chart title causing problem when issued from a do file

    I'm trying to control the chart titles for a large series of charts from a do file but am having a problem when the title text includes a comma

    For simplicity I've replicated the issue here using auto.dta

    When I type in a title with a comma directly it works fine (see uploaded png)

    Code:
    sysuse auto.dta
    
    graph bar (count), over(foreign) title("title row 1" "title, row2")

    When I save the graph command as a do file and then try to control the title text from a master do file it won't work because the comma is now seen as a comma. I've tried compound quotes but these do not stop the comma from being seen as a comma and triggering an error because it then expects an option after the comma (here being "option row is not allowed".

    do file 1: gphtest
    Code:
    graph bar (count), over(foreign) graph bar (count), over(foreign) title("`1'" "`2'")
    do file 2: gphmaster
    Code:
    do gphtest "title row 1" "title, row 2"

    Many thanks

    Gareth
    Attached Files

  • #2
    Hmm, I too find this perplexing. But to identify the problem a little more sharply, the error is actually being thrown by the do command itself, not by what your do-file is doing. That is, the problem is that Stata is parsing the line
    Code:
    do gphtest "title row 1" "title, row 2"
    in a way that makes it think that row is an option to the command do.

    To create another example: I don't even create a file called anything.do. I just type
    Code:
    . do anything
    file anything.do not found
    r(601);
    
    . do anything "hello there"
    file anything.do not found
    r(601);
    
    . do anything "hello, there"
    option there not allowed
    r(198);
    You can see how the third command threw an error similar to the one you were getting above. There seems to be something wrong with the way the do command is parsing its arguments. The same problem does not arise with programs:
    Code:
    capture program drop anything
    program define anything
        display  "`1'" _n "`2'"
    end
    
    . anything "hi, there" "hi, again"
    hi, there
    hi, again
    Perhaps this should be escalated to Stata Technical Services?
    Last edited by Hemanshu Kumar; 22 Oct 2025, 14:05.

    Comment


    • #3
      Thanks for looking at it Hemanshu and for your helpful elucidation of the issue.

      I will escalate it to Stata Technical Services as I know now that it looks like its not something that I'm doing wrong.

      Comment


      • #4
        I had a similar issue. I successfully used a workaround replacing the comma with the smcl ascii character command for the comma {c 44} in the title text.

        Comment


        • #5
          Thanks Glenn, that works so that's great, thank you.

          The reply I'd had from Stata Technical Services was "I have forwarded the issue to our developers. If there is a workaround or a possible solution in a future update, I'll let you know." but it seems this is the workaround.

          Comment

          Working...
          X