Stata 15 help for comments

[P] comments -- Add comments to programs

Description

This entry provides a quick reference for how to specify comments in programs. See [U] 16.1.2 Comments and blank lines in do-files for more details.

Remarks

Comments may be added to programs in three ways:

o begin the line with *;

o begin the comment with //; or

o place the comment between /* and */ delimiters.

Here are examples of each:

* a sample analysis job version 15.1 use census /* obtain the summary statistics */ tabulate region // there are 4 regions in this dataset summarize marriage

* a sample analysis job version 15.1 use /* obtain the summary statistics */ census tabulate region // there are 4 regions in this dataset summarize marriage

The comment indicator * may be used only at the beginning of a line, but it does have the advantage that it can be used interactively. * indicates that the line is to be ignored. The * comment indicator may not be used within Mata.

The // comment indicator may be used at the beginning or at the end of a line. However, if the // indicator is at the end of a line, it must be preceded by one or more blanks. That is, you cannot type the following:

tabulate region// there are 4 regions in this dataset

// indicates that the rest of the line is to be ignored.

The /* and */ comment delimiter has the advantage that it may be used in the middle of a line, but it is more cumbersome to type than the other two comment indicators. What appears inside /* */ is ignored.

Technical note

There is a fourth comment indicator, ///, that instructs Stata to view from /// to the end of a line as a comment and to join the next line with the current line. For example,

args a /// input parameter for a b /// input parameter for b c // input parameter for c

is equivalent to

args a b c

/// is one way to make long lines more readable:

replace final_result = /// sqrt(first_side^2 + second_side^2) /// if type == "rectangle"

Another popular method is

replace final_result = /* */ sqrt(first_side^2 + second_side^2) /* */ if type == "rectangle"

Like the // comment indicator, the /// indicator must be preceded by one or more blanks.


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