Announcement

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

  • Syntax question

    Dear All,

    is there any specific reason that I can write:
    Code:
    replace x=0 in L
    but I can't write:
    Code:
    replace in L x=0
    in Stata (17, but probably in all versions)??

    I am getting error 100: varlist required.

    In other words, how does one tell from the syntax diagram for replace that the order of if and in is flexible (they can be switched) but order of oldvar=exp and in is fixed (they can't be switched)??

    PS: both if and in are reserved words for the purpose of naming the variables, so whenever in (or if) is encountered in the command line, Stata should know to expect a corresponding expression to follow.

    Thank you, Sergiy

    Click image for larger version

Name:	syntax_replace.png
Views:	1
Size:	14.4 KB
ID:	1712351


  • #2
    Sounds like a great question for someone from StataCorp Jeff Pitblado (StataCorp) , perhaps. I can't think of a reason

    Comment


    • #3
      In my experience with Stata, there is a general rule (implied): What is documented is allowed, what is not documented might or might not be allowed. Following the documented syntax will never get you into trouble. Deviating from documented syntax, e.g., switching if and in, might get you into trouble -- nobody ever said or implied otherwise.

      As for the technical reasons, I would be interested, too. However, I doubt many Stata users want or need to know how exactly the syntax parser works.

      Comment


      • #4
        I doubt many Stata users want or need to know how exactly the syntax parser works.
        daniel klein , I agree. I don't want to know how the syntax parser works. I really want that version of the syntax (with changed order) to be working as well in the future versions of Stata, provided that there is no fundamental impossibility of doing this. Hence, was my question.

        Best, Sergiy

        Comment


        • #5
          Interesting question. There is advertised flexibility over Stata syntax. For example the order of option calls is immaterial. Also, if and in qualifiers can be in either order, if first or in first. I've never had occasion to try putting if or in qualifiers before the main syntax of generate or replace, but evidently it does not work.

          The chicken and egg question is that Stata allows whatever seems likely to be the way that Stata users will think about a command, but equally the way that Stata users will think about a command is influenced by what Stata allows. Natural language is similar in some respects but certainly not all. If I write "I a user of Stata am" anyone who can understand the rest of this post will be able to work out what I mean, and I don't think it's ungrammatical, but if it's likely to seem unidiomatic.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            For example the order of option calls is immaterial.
            I think that that is the basis of this case: both if and in are optional and the syntax diagram takes care to note that explicitly. The variable name & expression arguments preceding those are not.

            This isn't to say that you cannot find some other syntax diagram in the user's manual that is ambiguous as to what order is allowed and what is not.

            Comment

            Working...
            X