Announcement

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

  • Problem with Stata's parsing of command options in graphical commands

    Dear All, I suspect a bug in Stata's parsing of command options in graphical commands. Can someone confirm that this is still a problem in Stata 17?

    Code:
    version 16.0
    clear all
    sysuse auto
    
    graph bar , over(rep78), if foreign==1
    graph bar , over(rep78) , if foreign==1
    
    // END OF FILE
    Actual: first command succeeds, second command reports a syntax error.

    Expected: both commands produce identical output.

    Rationale: space before comma is meaningless and should be disregarded, like it is disregarded in other (non-graphing) Stata commands, for example:

    Code:
    table rep78 if foreign==1, c(mean price)
    table rep78 , c(mean price) , if foreign==1
    (Both commands work fine).

    Thank you, Sergiy Radyakin

  • #2
    Same issue with Stata-17. I guess the bug may be related to only with -graph bar-. Because -graph box- made no difference
    Code:
    gr box mpg, over(foreign), if foreign==1
    gr box mpg, over(foreign) , if foreign==1
    Roman

    Comment


    • #3
      Sorry for my curiosity: Is putting -if- after comma preferred to typing it before comma in some circumstances? According to the Syntax of -graph bar- and -table-, I would never know -if- could be after options (and thus would never try it). It seems allowing -if- to be after options is some kind of bug and needs to be corrected.

      Comment


      • #4
        I can confirm above observations under Stata 17. (The table example only works under version control because the syntax changed under Stata 17.)

        However, I am a bit puzzled. Is this syntax with the two commas documented anywhere? Is this an old syntax from an ancient Stata version that continues to work but is no longer documented?


        Edit: cross-posted with Fei Wang.
        https://www.kripfganz.de/stata/

        Comment


        • #5
          In an earlier discussion at this link Rich Goldstein wrote

          the actual rule in Stata is that parts of the command occur prior to odd-numbered commas and that options occur after odd-numbered commas; i.e., you are allowed to have more than one comma but need to be careful what you put where; note, however, that there may be some official commands that do not abide by this (there are many community-contributed commands that break this)
          but does not address the question asked in post #4 here regarding documentation for this feature.

          Added in edit: Aha! Section 11.1.7 of the Stata User's Guide PDF tells us (sorry for the picture, copy-and-paste fails to copy underscore characters for me).

          Click image for larger version

Name:	Screen Shot 2021-11-09 at 9.36.10 AM.png
Views:	1
Size:	149.0 KB
ID:	1635648


          Last edited by William Lisowski; 09 Nov 2021, 07:37.

          Comment


          • #6
            Originally posted by Fei Wang View Post
            Is putting -if- after comma preferred to typing it before comma in some circumstances?
            Yes, most commonly in the situation like:

            Code:
            `command'
            `command' , if foreign==1
            `command' , if foreign==0
            where the command in the macro includes options after comma. Writing it this way improves readability sometimes, but it is not impossible to change the sequence of course to put the options at the end.

            Importantly, the spaces are meaningless in the syntax, but here somehow it matters and this created a situation rather difficult to debug.


            Originally posted by Sebastian Kripfganz View Post
            Is this syntax with the two commas documented anywhere? Is this an old syntax from an ancient Stata version that continues to work but is no longer documented?
            I am afraid I can't recall where I picked this as a possibility, but a lot of do/ado code passes in front of my eyes, so the source is not necessarily unique. I can't pinpoint any documentation page as a source for such a syntax modification, but it works throughout, and is useful sometimes.

            Comment


            • #7
              Thank you, William Lisowski for pointing the appropriate documentation page to confirm such a use case is valid.

              Comment


              • #8
                Never heard of that before. Using if in this way is like an elementary school student solves equations of homework by linear algebra, his classmates and even teachers will judge the process as wrong, but actually it is indeed right.

                Comment

                Working...
                X