I am working on a .do file created by someone else. This person used a semicolon delimiter in the entire file. I am trying to go through this file and see what is going on. I like to do this by selecting a portion of the code and hitting the "Execute Selection (do)" button. However, the delimiter seems to be messing up this. Are there any workarounds for me?
-
This shouldn't cause any problems...have you set your delimiter by `#delimit ;` before you run any of the selections? – Micah Smith Oct 28 '14 at 14:54
-
I cannot use ``#delimit ;`` in the command line. If I run a selection from the .do file, I think I must have ``#delimit ;`` as part of the selection, which isn't going to happen as it would be super annoying to always include this at the beginning of every selection. – bill999 Oct 28 '14 at 14:58
2 Answers
Suppose your do-file looks like this:
#delimit ;
set obs
10 ;
gen x = _n ;
gen y = x^2 ;
gen z = x
^3;
Anytime you highlight a selection and press "Execute selection (do)", Stata creates a temporary, self-contained do-file, with default delimit at cr
and runs that:
"When a do-file begins execution, the delimiter is automatically set to
carriage return, even if it was called from another do-file that set the
delimiter to semicolon."
It does not sequentially run those commands from the console. Therefore, if you select the first 2 commands in the do-file above, the temporary do-file includes a call to #delimit
whereas if you selected the last 2 commands, the temporary do-file would not have this call and would throw a syntax error for two line commands.
One solution could be to copy-paste selections to a fresh do-file that just had the #delimit
command at the beginning, and then run that.
You could also write a script to rid your do-file of semicolons. If a line does not end in a semicolon, then append the next line to the end of the current line, and check this line again. Depending on how complex the syntax is in your do-file, this would be more or less difficult.

- 4,203
- 22
- 28
-
I would like to get rid of the semicolons, but the file is very long. I found something similar to your suggestion of creating the fresh do-file and copying and pasting. It suggested to create a profile.do file and include ``#delimit ;`` in it. Would this work? I found this suggestion [here](http://stackoverflow.com/questions/5985751/how-to-execute-multiple-line-selection-in-do-file-editor-of-stata). If it would work, where would I store the profile.do file and would I need to delete it when working on other do files not involving ``delimit`` stuff? – bill999 Oct 28 '14 at 15:24
-
You could try that but I don't think it will work. `profile.do` gets run at the beginning of every Stata session, not when a new do-file is run. As soon as you run a do-file that does not have the `#delimit` command in it, it is by default set to `cr`. – Micah Smith Oct 28 '14 at 15:30
-
Gotcha. Thanks for all the help. It sounds like the best thing to do is to replace everything and avoid using the delimit in the future. – bill999 Oct 28 '14 at 15:31
-
1That seems best in this case. The `;` delimiter can be helpful, especially if you are writing very long commands, and causes problems only in the "execute selection"...so basically pick one of delimiter/execute selection that you want more – Micah Smith Oct 28 '14 at 15:38
Another option is comment out the lines you have already ran by enclosing them with /* */
and to use exit;
where you want to stop. You do have to be a little careful with local macros.

- 9,077
- 2
- 25
- 50