0
votes

I typically work in another text editor and simply copy and paste my work into Stata's command prompt. However, I have noticed a difference between the way the command prompt and the do file editor handle comments.

The code below reproduces the things I have discovered:

mata
//test comment
/* test comment 2 */
end

//test comment 3
*test comment 4
/* test comment 5*/

When run from the do file editor, the code runs without issue.

But when I run it after copying and pasting into the command prompt, I receive a number of r(3000) errors in mata and r(199) errors in Stata.

The sole exception is that the * comments in regular Stata work fine in both interfaces.

I also see that the // comment in mata gives an "expression invalid" error message along with the r(3000) notification, but I only receive the r(3000) message when I use the /* text */ comment. In regular Stata, both comment types that are not * give "/ is not a valid command name" messages along with the r(199).

My main question is:

  • What is the reason behind this difference? Is there anything I can do to suppress these errors?

Also, this is something like a red flag for me:

  • Are there other behaviors that differ when I run things via the command prompt rather than the do file editor?
1

1 Answers

4
votes

The following Technical Note from the 16th Stata manual about Do-files explains:

"...The /* */, //, and /// comment indicators can be used in do-files and ado-files only; you may not use them interactively. You can, however, use the ‘*’ comment indicator interactively..."

So there is nothing surprising here. You can easily prevent errors like these by following the conventions. Just read the relevant section of the aforementioned manual for more details.

Only StataCorp knows for sure, but such differences probably arise from how Stata interprets the code internally when this is parsed from a do file or the command prompt.

See the following post for another (unrelated) example of an inconsistent behaviour:

Personally, after using Stata extensively for years, i have not noticed any other major differences when running code from do files and interactively.