Comment Lines |
A line with * as the first non-blank character is treated as a comment and is ignored. We use comments rather extensively in the examples to help you understand the programs. For instance:
*
* Do basic statistics on the two subsamples. The first is where "male" is
* non-zero, the second where .not.male is non-zero, that is, where male
* itself is zero.
*
stats(smpl=male) wage
stats(smpl=.not.male) wage
The * doesn't have to be in the first column on the line, just the first non-blank character. So, for instance,
do i=1,%ncmom
*
* Do the label for variable I
*
report(use=creport,atcol=1,atrow=2*i) %eqnreglabels(vars)(i)
do j=1,%ncmom
which indents the comments to match the indenting of the line to which they apply.
Comment Blocks
You can also mark an entire block of lines as a comment by using the symbol /* to mark the beginning of the block, and */ to mark the end of the block. (Note: the /* must be the first (non-blank) characters on the lines). While this provides a convenient way to enter several lines of comments, it is probably most useful commenting out an existing block of instructions. For example:
* This is a comment line
/*
This is a comment block
linreg y
# constant x1
*/
linreg y
# constant x1 x2
This skips the first regression, but does the second.
Tips on Using Comments
Your first goal is always to get the calculations correct. However, if you have a program (or part of one) that you expect that you might need again or that others might want to read or use, it’s a good idea to add comments describing what each section of code does.
Also, if you have a part of your program which you’re not sure is correct, commenting it can often help you spot errors. (If you can’t explain why you’re doing something, that might be a good sign that you’re doing it wrong).
Now it’s possible to overdo the comments. You may have seen some programs with a very elaborate comment block like:
*****************************************************
* This is a program that analyzes the population *
* of kangaroos in New South Wales. *
*****************************************************
RATS provides several ways to help manage larger blocks of comments. The first are the comment block symbols. So
/*****************************************************
This is a program that analyzes the population
of kangaroos in New South Wales.
******************************************************/
gives a similar appearance to the block above, but you can more easily edit the comments as you don’t have to worry about having the * symbols at the start of each line.
Edit Menu, Comments operations
The Edit menu provides operations for commenting or un-commenting sections of your code. The Edit—Comments—Format Comments operation takes a selected block of text and creates a set of one or more comment lines of roughly equal length (except for the final line). If some of the lines are already comments, the *’s and leading blanks are stripped out before the lines get formatted. As an example, we pasted in the first two sentences from this paragraph as a single line and did the Format Comments operation. The result is
* The Edit menu provides operations for commenting or un-commenting sections of
* your code. The Edit—Comments—Format Comments operation takes a selected block of
* text and creates a set of one or more comment lines of roughly equal length
* (except for the final line).
The desired line length can be set on the Editor tab in the Preferences dialog. The comments above used a line length of 80, to fit the page, somewhere around 70-80 seems to work best. Note that the comment length isn’t a hard limit. In order to roughly balance the lines, it might go a bit above that.
There are two other Comments operations on the Edit menu. Edit—Comments—Comment-Out Lines takes the selected text and inserts * at the beginning of each; converting each into a comment. The reverse is Edit—Comments—Uncomment Lines, which strips the lead * off any line which has one. These allow you to take a block of lines out of the execution and put them back in.
Copyright © 2025 Thomas A. Doan