Announcement

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

  • Syntax for the * comment

    Stata has two types of single-line comments: // and *. The comment // has identical syntax to single-line comments used by, e.g., C and R. However, while * can be placed anywhere on a line, it cannot be placed after code. For example:

    Code:
    * This is a valid comment
       * This is a valid comment
    gen var = 3 * This is not a valid comment
    gen var = 3 // But this is a valid comment
    I am aware of some languages, like Fortran, that require comments at a certain place in the column. Are there examples of other languages that have a single-line comment syntax like Stata's *, which can be placed anywhere on the line but not after code?
    Last edited by Julian Reif; 27 Dec 2020, 07:25.
    Associate Professor of Finance and Economics
    University of Illinois
    www.julianreif.com

  • #2
    The single-line comment with * cannot be placed after code, because the "*" becomes a multiplication operator and does not work anymore as a sign for the beginning of a comment. It is probably a case of operator overloading. Whether it was good a choice to overload * to use it in two different contexts for two completely distinct functions is probably up to debate.

    Comment


    • #3
      We should note that only the * comment is valid when used interactively; the // comment and the /* ... */ comment (not mentioned in post #1) are allowed only in programs.

      For a more complete discussion, see the output of
      Code:
      help comments

      Comment


      • #4
        As a comment, rather than a complete answer to the question: when I wrote programs in Fortran IV in the 1970s, then usually called FORTRAN IV, a C character in the first position of a line turned the line into a comment.. A quick Google suggests more flexibility in recent versions.

        Comment

        Working...
        X