Stata 和 Mata 中的评论:文件编辑器与命令提示符
Comments in Stata and Mata: Do file editor vs command prompt
我通常在另一个文本编辑器中工作,只需将我的工作复制并粘贴到 Stata 的命令提示符中。但是,我注意到命令提示符和 do
文件编辑器处理注释的方式不同。
下面的代码再现了我发现的东西:
mata
//test comment
/* test comment 2 */
end
//test comment 3
*test comment 4
/* test comment 5*/
当 运行 来自 do
文件编辑器时,代码 运行 没有问题。
但是,当我将其复制并粘贴到命令提示符后 运行 时,我在 Stata 中的 mata
和 r(199)
错误中收到许多 r(3000)
错误。
唯一的例外是常规 Stata 中的 *
注释在两个界面中都可以正常工作。
我还看到 mata
中的 //
评论给出了 "expression invalid" 错误消息以及 r(3000)
通知,但我只收到 r(3000)
当我使用 /* text */
评论时的消息。在常规 Stata 中,两种非 *
的注释类型都会给出“/ is not a valid command name”消息以及 r(199)
.
我的主要问题是:
- 造成这种差异的原因是什么?我能做些什么来抑制这些错误吗?
此外,这对我来说有点危险:
- 当我通过命令提示符而不是
do
文件编辑器 运行 时,是否有其他不同的行为?
来自 16th Stata manual about Do-files 的以下 技术说明 说明:
"...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..."
所以这里没有什么奇怪的。您可以通过遵循约定轻松地防止此类错误。请阅读上述手册的 the relevant section 了解更多详情。
只有 StataCorp 确切知道,但这种差异可能源于 Stata 在从 do
文件或命令提示符解析代码时如何在内部解释代码。
有关不一致行为的另一个(无关)示例,请参阅以下 post:
就个人而言,在广泛使用 Stata 多年之后,我没有注意到 运行 来自 do
文件的代码和交互方式的任何其他主要差异。
我通常在另一个文本编辑器中工作,只需将我的工作复制并粘贴到 Stata 的命令提示符中。但是,我注意到命令提示符和 do
文件编辑器处理注释的方式不同。
下面的代码再现了我发现的东西:
mata
//test comment
/* test comment 2 */
end
//test comment 3
*test comment 4
/* test comment 5*/
当 运行 来自 do
文件编辑器时,代码 运行 没有问题。
但是,当我将其复制并粘贴到命令提示符后 运行 时,我在 Stata 中的 mata
和 r(199)
错误中收到许多 r(3000)
错误。
唯一的例外是常规 Stata 中的 *
注释在两个界面中都可以正常工作。
我还看到 mata
中的 //
评论给出了 "expression invalid" 错误消息以及 r(3000)
通知,但我只收到 r(3000)
当我使用 /* text */
评论时的消息。在常规 Stata 中,两种非 *
的注释类型都会给出“/ is not a valid command name”消息以及 r(199)
.
我的主要问题是:
- 造成这种差异的原因是什么?我能做些什么来抑制这些错误吗?
此外,这对我来说有点危险:
- 当我通过命令提示符而不是
do
文件编辑器 运行 时,是否有其他不同的行为?
来自 16th Stata manual about Do-files 的以下 技术说明 说明:
"...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..."
所以这里没有什么奇怪的。您可以通过遵循约定轻松地防止此类错误。请阅读上述手册的 the relevant section 了解更多详情。
只有 StataCorp 确切知道,但这种差异可能源于 Stata 在从 do
文件或命令提示符解析代码时如何在内部解释代码。
有关不一致行为的另一个(无关)示例,请参阅以下 post:
就个人而言,在广泛使用 Stata 多年之后,我没有注意到 运行 来自 do
文件的代码和交互方式的任何其他主要差异。