How to Use /// Correctly

By Annabella Tyrrell · Published 13 November 2026
Programmingstata

When writing long commands in Stata, splitting code across multiple lines can make do-files easier to read and organise. The /// line-continuation marker allows a command to continue onto the next line without Stata treating it as a separate command. However, placing /// incorrectly can cause syntax errors or unintentionally combine commands. Understanding where to use it, and where to avoid it, helps ensure your do-files run as intended.

For these examples, we use Stata’s built-in automobile dataset:

sysuse auto, clear

Correct uses of ///

Continuing long commands

One of the most common uses of /// is to divide a long command into multiple lines. For example, we can run a regression with several explanatory variables and an additional option:

regress price mpg weight ///
     i.foreign, vce(robust)

The /// tells Stata that the command continues on the following line. Both lines are interpreted as a single regression command.

Separating graph elements and options

Graph commands often contain several elements and formatting options. Using /// makes these easier to organise:

twoway (scatter price mpg) ///
        (lfit price mpg), ///
        title("Price and mileage") ///
        legend(off)

Each continuation marker joins the following line to the same command, allowing the graph elements and options to be written separately without changing the result.

Splitting expressions and conditions

The marker can also separate an expression from its conditions:

generate byte expensive = price > 6000 ///
     if !missing(price)

Here, the if qualifier remains part of the generate command, even though it appears on a different line.

Adding comments after ///

Because /// also acts as a comment indicator, any text following it on the same line is ignored:

regress price mpg /// Continue with additional variables
     weight i.foreign

Stata ignores the explanatory text and joins the two lines into one command. This can be useful for documenting code, although separate comments are generally clearer for longer explanations.

Incorrect uses of ///

Between separate commands

A common mistake is adding /// after a complete command when the next line should execute independently.

Incorrect:

summarize price /// summarize mpg

Stata attempts to interpret both lines as one command, rather than running two separate summaries.

Correct:

summarize price 
summarize mpg

Each command now executes independently.

Replacing /// with //

Although they look similar, // and /// have different purposes. The double-slash marker comments out the remainder of the current line but does not continue the command.

Incorrect:

regress price mpg // Additional variables weight i.foreign

Stata runs the first regression and then attempts to interpret weight i.foreign as a new command.

Correct:

regress price mpg /// Additional variables
     weight i.foreign

The three slashes ensure that both lines belong to the same regression.

Splitting variable names

The /// marker joins lines as separate pieces of code; it does not reconnect words or variable names that have been divided.

Incorrect:

summarize pri /// ce

Stata does not reconstruct price from the two fragments.

Correct:

summarize price

Always place the continuation marker between complete elements of a command, rather than within a variable name or other individual token.

Omitting the space before ///

Stata requires the continuation marker to be preceded by whitespace.

Incorrect:

regress price mpg/// weight

Correct:

regress price mpg ///
     weight

Separating /// from the preceding code ensures that Stata recognises it correctly.

Using /// in the Command window

The /// marker is designed for do-files and ado-files, not for commands entered interactively in Stata’s Command window.

For example, this code is valid when executed from a do-file:

regress price mpg ///
     weight i.foreign

However, entering the lines separately in the Command window does not provide the same line-continuation behaviour. Instead, enter the complete command on one line:

regress price mpg weight i.foreign

Key considerations

The most important distinction is that /// continues an existing command rather than starting a new one. While it is typically placed at the end of a line, Stata also permits it on a line of its own to join surrounding code.

When using ///, ensure that the following line is intended to form part of the same command, that the marker is preceded by whitespace and that variable names or other individual tokens remain intact.

Correct placement helps keep longer do-files readable, organised and free from avoidable syntax errors.

9 views 0 found this useful