Announcement

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

  • Why is the word "with" a reserved word?

    Dear Statalisters,

    just a curiosity, why is "with" a reserved word and can't be used for variable names?
    I assume there is some historic reason, which I am not aware of.
    Or are there existing commands that use with in their syntax?

    Thank you, Sergiy Radyakin

  • #2
    Sergiy,

    Good question. I don't think it is a reserved word issue, however. Consider the following, all of which work OK:

    Code:
    gen gen=0
    gen generate=0
    gen replace=0
    The reason gen str10=0 doesn't work (apropos your previous post) is that it is using the "str10" as the variable type but then there is no variable to generate. Similarly, trying to use if and in as variable names fail because the syntax is not correct, not because they are reserved, per se. In fact, there is no mention in help varname about the illegality of using reserved words as variable names.

    This doesn't answer your question, but might refine your search for an answer.

    Regards,
    Joe

    Comment


    • #3
      Joe, Data Management volume on page 360 lists the reserved words that cannot be used as variable names:
      _all, _b, byte, _coef, _cons, double, float, if, in, int, long, _n, _N, _pi, _pred, _rc, _skip, strL, using, with, and str#
      Here str# stands for str1, str2, ... str20000, etc.
      Same list is in the User's Guide, page 88, so it is not a typo. A test whether it is reserved or not is to try actually make a variable with that name. And it is indeed rejected by Stata if I try to code:
      Code:
      . generate with =1
      =exp required
      r(100);
      I have used in practice of programming all of the above, except "with" or at least I couldn't recall it when I started thinking about each element of the list consciously.
      generate, replace etc are not reserved names. I don't have any problems with them. They can be used as variable names, local names, etc. Though it may be confusing and I wouldn't recommend it.

      Best, Sergiy

      Comment


      • #4
        Sergiy,

        Thanks for the reference. I didn't realize you had already established that there was a list of reserved words that cannot be used as variable names. For the most part, this list makes sense in that they are either reserved constants or tokens whose use in that context would be ambiguous. It's odd to me, however, that this list is not contained in help varname (which is where you end up if you do help gen and click on newvar).

        The error message when trying to use with as a variable name isn't as informative as that when trying to use a data type as a variable name or when trying to use if and in. Those messages all assume you meant to use them in their proper context and failed. The error message for with doesn't help suggest a proper context.

        Happy trails,
        Joe

        Comment


        • #5
          There seems to be a very early from of replace for which the syntax was

          Code:
          replace varname with values
          Bill Gould mentions this in an interview here (p. 20).

          Best
          Daniel

          Comment


          • #6
            Dear Daniel, thank you very much for the reference, this is precisely what I was looking for. Interestingly it doesn't work even under version 1.0 statement in Stata 13. But from the interview I see that that was an internal version of the language, so perhaps even prior to 1.0. Best, Sergiy.

            Comment

            Working...
            X