Stata Help

The Basics of Syntax in Stata

While there is a large variety of commands in Stata, and new commands can be programmed by anyone, there are a few basic concepts that will hold true in basically every Stata command. By knowing these basics, you can quickly and easily learn new commands and execute famiiar ones.

A Stata command has approximately three major parts.

The first part is the command itself, for example browse which launches the data browser.

From there, you can add the second part, variable arguments. For example, if you are using the browse command, this could take the form of a single variable you want to browse browse [variable] but can also involve multiple variables, browse [variable] [other variable]

This will cause a data browser to open up with multiple variables specified. In this and in every Stata command, you do not use the full variable name, but rather the short name that is displayed in the Variables window.

The third part of a Stata command is options. While browse takes "if" arguments (browse gpa if homelang==1 would only show the GPA data pertaining to English speakers) it does not have options the way most commands do. For this example, then, if you wanted to summarize gpa but were interested in a more complete summary than what is normally presented, you would use the detail option. So the final command, with options included, is summarize gpa, detail. Notice that the command requires a comma before the options begin. This comma is entirely necessary and Stata will not properly process optional subcommands without a comma between them and the main command argument.

To see what options a command has, type help [command] This will bring up a Help Viewer which includes sample syntax for the command in question and a complete list of command options.

There are a few options that are common to most Stata commands and do not require a comma before use. To learn more about their specifics, select one below:

Additionally, the majority of commands and options can be shortened. Here is a brief overview of Stata's command abbreviation guidelines.

Back