Announcement

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

  • skip lines of code in do file

    Hi,
    Is there any way to skip some lines of codes in a do file? As an example, I want to run codes from 1 to 49 and continue it from line 71 to 100! except using /* */ command!
    Thanks

  • #2
    Sometimes I do this:
    Code:
    . display "do this"
    do this
    
    . if 0 {
    .         display "don't do this'"
    . }
    
    . display "also do this"
    also do this
    
    .
    The if 0 (see help ifcmd) will excute the block of code if 0 is not false; that is, if 0!=0; that is, never.

    You can change 0 to 1 without changing anything else and the the code will execute.
    Last edited by William Lisowski; 04 Aug 2021, 15:48.

    Comment


    • #3
      Just out of curiosity, since /* */ is probably the simplest way of skipping execution of part of a do-file, why do you specifically want to not use that?

      Comment


      • #4
        It sounds like you might have some logic for the "skip" that you aren't telling us. If that's the case, the if/else structure hinted at by William is a direct approach. If it's simply a shortcut for testing code, then there shouldn't be any issue in commenting it out, or otherwise bypassing it with an impossible to execute if block.

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          Just out of curiosity, since /* */ is probably the simplest way of skipping execution of part of a do-file, why do you specifically want to not use that?
          Clyde - Using /* */ is not my first choice because it makes an entire section colored green and difficult to read when you want to follow certain codes in those skipped lines.

          Comment


          • #6
            Originally posted by William Lisowski View Post
            Sometimes I do this:
            Code:
            . display "do this"
            do this
            
            . if 0 {
            . display "don't do this'"
            . }
            
            . display "also do this"
            also do this
            
            .
            The if 0 (see help ifcmd) will excute the block of code if 0 is not false; that is, if 0!=0; that is, never.

            You can change 0 to 1 without changing anything else and the the code will execute.
            Thanks, William, it worked perfectly. I wish Stata guys make a more direct solution for this so that one could skip some lines with integrated commands. Anyways, thanks again.

            Comment


            • #7
              Interesting! My initial response was to say, "why don't you just change the color setting for comments in the do-editor" but when I went to try it myself, it appears that this is not something you can do.

              Comment


              • #8
                Originally posted by Clyde Schechter View Post
                Interesting! My initial response was to say, "why don't you just change the color setting for comments in the do-editor" but when I went to try it myself, it appears that this is not something you can do.
                Well, even if you could change the green color to a more easier-to-read color, say black, the problem is not solved yet. Using /* */ will make the color monochromic anyway.

                Comment

                Working...
                X