Comments can be more useful than you think. While the commands tell Stata what to do, the comments remind ourselves or the readers what we have been doing.
Depending on one's preference, there are three ways to indicate comments in Stata.
*this is a comment
//this is a comment
/* this is a comment */
//this is a comment and /* this is a comment */ are used in do-files.
Anything commented by // and /* */ will not be executed.
We use comments to annotate our codes, reminding ourselves of why we did one thing and helping our collaborators understand what we did.
. sum length if price > 10000 & !missing(price) //make sure only nonmissing cases are used.
/* */ can be used in the middle of the commands to comment out the commands. For instance,
. list make if price > 10000 /*|rep78 <= 2 */ if we are testing alternative codes and not sure yet if we want to run the piece of codes in /**/.
To make our long commands readable, use /// to tell Stata that the command continues to the next line and everything following the continuation lines is part of the commands.
. sum length if price > 10000 ///
& rep78 <= 2 ///
& make !="Audi Fox"
We may want to start our do-files with the information of title, author, date etc. using comments.
* project
* author, date
Comments can divide our codes into different parts to make long scripts more readable.
**************
//model1
some commands
**************
//model2
more commands