[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: comment out a number of lines together

From   Steven Samuels <>
Subject   Re: st: comment out a number of lines together
Date   Thu, 2 Oct 2008 15:27:31 -0400

Here's another example where * works and // doesn't. The circumstances: the delimiter is ";", and the code block contains a - forvalues- or -foreach- section. /* and */ around the -foreach- section also works.


*****************CODE BEGINS****************
sysuse auto, clear
forvalues i=1/5 {
di "rep78 = " `i'

#delim ;

forvalues i=1/5 { ;
di "rep78 = " `i';

***************** (*) COMMENT WORKS ****************
* forvalues i=1/5 { ;
* di "rep78 = " `i';
* };
* ;

***************** // COMMENT FAILS****************
// forvalues i=1/5 { ;
// di "rep78 = " `i';
// };
// ;
*****************CODE ENDS****************

On Oct 2, 2008, at 12:44 PM, Nick Cox wrote:

Very good catch, Sergiy. Thanks for the correction! I should have
checked about the //.
Conversely, this is another argument for the deprecated *.


Sergiy Radyakin


local c //
will not work in the program because "//" is interpreted as the start
of the comment
it works in the command line though, because "//"-style comments are
prohibited in the command line input. To fix this:
1) open quotes before // like so: local c "//" , or
2) write it down as an expression, e.g. local c="/"+"/"
In any case, Stata fails to recognize "//" as a comment when it comes
as a result of macro expansion. But it works for a star ("*").

// --- begin of file ---
local c //
display `"`c'"'
local c ="/"+"/"
display `"`c'"'
local c "//"
display `"`c'"'
local c "*"
display `"`c'"'
 `c' just nothing
local c "//"
 `c' just nothing
// --- end of file ---

If writing out debugging messages, it may be more comfortable to use
di_g. See: help di_g.

Best regards, Sergiy Radyakin

On Tue, Sep 30, 2008 at 11:28 AM, Nick Cox <> wrote:
Another is to prefix lines by e.g.



local c *


local c //

comments out those lines.


local c

zaps the macro.

Naturally any definition of the local as "*" or "//" must precede all
that require that interpretation.

The converse does not apply: if the local is not defined, Stata sees

More generally, you can define or undefine the macro at will.

I don't especially recommend this method, but it is an alternative
that is
sometimes useful, and it matches practices in many programming

Maarten buis wrote:
--- Paul O'Brien <> wrote:

at times i need to comment out a number of lines, usually with * and
remove the * later to activate the commands.
is there a simple way to remove and add the * to a number of line at
One way to comment out a block of code is to surround them with /*
*/ this way you have to remove only these two.
*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index