Announcement

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

  • Wrapping lines in the do file

    Hi friends,

    I am trying to wrap long lines of code in my .do file text to make it less cumbersome to interact with. I have tried several methods including adding "///" at the end of each line to continue it down (as discussed in this post), but it did not work. Specifically, I am typing a long line of code like this:

    keep [var1] [var2] [var3]...... ///
    [var4] [var5]

    Such that I need to go to the next line to keep all the variables I'm keeping on the page. When I use the "///" method, Stata still does not recognize the second line as a continuation of the previous "keep" command. I am using Windows version 13. Thank you in advance for any advice.

  • #2
    It would be helpful if you posted what you actually typed and what Stata returned. Even better would be to give an example with data set that is accessible to everyone. Note, you could also change the delimiter - see http://www.stata.com/help.cgi?delimit

    Comment


    • #3
      Hi Scott, thanks for your reply.

      I entered the following code into Stata from my do file:

      keep age sexpre condcun condiai condio condvi matspcondom fsp2mpacu fsp2mpvcu msp2mapcu msp2mpacu condiai2 condio2 condvi2 risk2 risk2a risk2b riskc2 ///
      risk1 risk3 risk4 risk5 risk6 risk7 risk8 riskc16 riskc13 riskc12 riskc11 riskc10 sp60d sp60diai sp60dvi splife splifeiai splifevi depressn cesd10dep ///
      cesd1 cesd2 cesd3 cesd4 cesd5 cesd6 cesd7 cesd8 cesd9 cesd10 cesd10score studyid status


      The error that is returned is the following:
      unrecognized command: risk1
      unrecognized command: cesd1


      This is because Stata thinks that the next variables I am keeping on the second and third lines (risk1 and cesd1) are new commands, and not a continuation of the "keep" command.

      I also tried the "delimit" option but got a similar error.

      Comment


      • #4
        Chris Hearne Does your do file highlight "///" in green colour?

        Comment


        • #5
          Please use code delimiters (see FAQ). Otherwise, it is difficult to determine where the line ends b/c the browser will wrap the text.


          You say
          I entered the following code into Stata from my do file:
          . Do you mean that you ran that code from your dofile either with the command
          Code:
          do mydofile.do
          , or by pressing the "do" button in Stata's do file editor? OR, did you copy the text from your do file and enter in into the command line?

          Using comments (see help comments) and delimit to break up long longs only works in do-files, not from the command line. The following works fine from a do file:

          Code:
          sysuse auto, clear
          keep make ///
              price ///
              mpg 
          
          keep make /*
          */ price /*
          */ mpg
          
          #delimit ;
          
          keep
            make
            price
            mpg 
          ;
          #delimit cr


          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment


          • #6
            Carole, that worked great. I didn't realize that it wouldn't work if I copy/pasted the code into the command line. Thank you.

            Comment

            Working...
            X