Announcement

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

  • "#delimit ;" combined with "*" produces no output

    Hello everyone

    I have a very simple frustrating problem, for which I found a solution I don't understand, and I couldn't find a post about it anywhere so I am making one here so others can google and hopefully not was time figuring it out themselves.

    Problem: using "*" as comments, within a section where ";" is set as delimiter, messes with some commands such that they make no output.
    - i have just taken out the part of the code that doesn't work. Making graphs with several lines of code work as normal with "*"

    1) Code that doesnt create any output:
    Code:
    #delimit ;
          
        * PREDICT FORECAST
                predict std_f, stdf;
            
    #delimit cr
    2) Code that works as normal
    Code:
    #delimit ;
          
        // PREDICT FORECAST
                predict std_f, stdf;
            
    #delimit cr
    I have seen posts on how complicated the commenting in stata can get, but not on this issue of "*" creating a problem like this.

    I hope this post is not too trivial, but I would like to understand why (1) doesnt work.

    Best regards,
    Henrik

  • #2
    Since your declared rule is that semi-colons end command lines it follows that

    Code:
    * PREDICT FORECAST            
    predict std_f, stdf;
    is to Stata equivalent to

    Code:
    * PREDICT FORECAST  predict std_f, stdf;
    and the two physical lines are thus one logical command, a comment.

    (Leading spaces are naturally immaterial here.)

    But there's still an apparent inconsistency, I agree, and that's down to StataCorp to explain, or somebody else to say what I am not seeing.

    When the // syntax was introduced, it wasn't implemented in quite the same way, and I don't have a story there.
    Last edited by Nick Cox; 22 Aug 2019, 05:15.

    Comment


    • #3
      Thank you for your reply.

      That makes sense. I will just use "//" for now, or "*" with ";"

      The code below works such that it creates "std_f", and "ci_lf", and doesn't do the graph. So it seems like "*" acts like something halfway between "//" and "/*", and one would have to use ";" after "*" in this situation.
      [
      CODE]
      #delimit ;

      * PREDICT FORECAST;

      predict std_f, stdf ;

      * GEN VARS FOR THE FORECAST LINES

      gen ci_uf = y_hat + invttail(_N-2,0.025)*std_f;
      gen ci_lf = y_hat - invttail(_N-2,0.025)*std_f;

      * TWOWAY SCATTER

      twoway lfitci bweight estriol
      || scatter bweight estriol
      || line ci_uf estriol, color(red)
      || line ci_lf estriol, color(red)
      , xlabel(10 (5) 25) xmtick(7 (1) 27)
      ylabel(15(5)45) ytitle("Birth Weight (g/100)")
      legend(off);
      #delimit cr[/CODE]

      But if I use just "//" instead of "*", there is no problem.

      Comment


      • #4
        Hard for me to say more. End-of-line characters might be driving this.

        It's not the answer you want but I never use semi-colons like this in Stata code and puzzling examples feed my prejudice. It's one thing to find them convenient for occasional very long commands. It's quite another to have to type them every <very mild expletive> time. And switching delimiters looks very ugly to me. So, continuations yes, semi-colons just say no.

        Except in writing: I love semi-colons but find students -- even at my university, which has pretty high standards -- almost never use them and are extremely fuzzy about when they could or should be used. That's not just a generation gap; it's two or three.

        And Mata is a different story.

        Comment


        • #5
          I agree with the semi-colons.

          In terms of stata code I just use a text-editor and make my own snippets so I don't have to type repetitive stuff.
          That way I don't have to align the "///" signs every time I change the content of multi-line commands. Just have to remember to put an ";" at the end.... and not use "*".

          In terms of writing, I have been told by teachers that they are used seldomly and can be confusing, so I find them exactly that. Rare and confusing. So I avoid them to be safe (I think most people my age and below are like that). Anything I have been told is confusing always will be a bit confusing to me - like a confusing first-hand impression of a person.

          Comment


          • #6
            it's hard to ignore teaching convincingly given. Formative years for me included ages 11-17 in secondary school; no teacher of ours who purported to know anything about English would have tolerated split infinitives ("to boldly go") in our writing. 50 years on, I still avoid split infinitives even though I realise that the argument against them was bogus even when my teachers were themselves being taught. I avoid split infinitives because many well educated people were taught more or less what I was taught and I don't want readers to think I don't know about split infinitives.

            But semi-colons? Just say yes.

            A splendid essay by Lewis Thomas on punctuation is widely copied: e.g. http://www-personal.umich.edu/~jlawler/punctuation.html

            Comment


            • #7
              Just came across this problem. This code outputs '2' and '3', but not '1'.
              Code:
              #delimit;
              
              * comment 1
              di 1;
              
              // comment 2
              di 2;
              
              /* comment 3 */
              di 3;
              The manual should be updated to mention this.

              Comment

              Working...
              X