Stata for Linux

Stata is a general purpose, statistical and matrix-oriented, data management package from StataCorp based in College Station, Texas.

1. Availability

Sociology maintains a 10-user, network Linux license for Stata SE (Special Edition), Version 15 on compute server charisma. A Sociology Linux account is required for use.

2. Access Requirements

Windows users need the following:

Prior to opening a Stata session:

  1. Load X-Win32. This makes X11 services available on your PC.
  2. Load PuTTY and open a termnal session to

Mac users:

Linux users:

3. Versions of Stata

The Sociology Stata installation includes two versions of Stata -- large data set Stata/SE and small data set Stata/IC. Their constraints are:




Modification of Default

Default number of variables



set maxvar #

Maximum number of variables



Maximum string variable size



Default size of matrices

400 x 400

200 x 200

set matsize #

Maximum size of matrices

11,000 x 11,000

800 x 800

Stata 12 provides automatic memory management and is able to adjust its memory usage up or down as required by the data in use.

4. Invoking Stata

Stata for Linux has two user interfaces. The preferred is a graphical user interface termed Stata(GUI). The second is a nongraphical user interface termed Stata(console), which runs within an SSH terminal window. The following invocations are available from the terminal command line.



xstata &

Starts Stata/IC in Stata(GUI) mode and returns the terminal command line prompt

xstata-se &

Starts Stata/SE in Stata(GUI) mode and returns the terminal command line prompt


Starts Stata/IC in Stata(console) mode


Starts Stata/SE in Stata(console) mode

A Stata(GUI) session appears below. Commands are typed in the lower, middle Command window. When Enter is pressed, the command is executed in the Results window and output appears below the command. When output exceeds the size of the Results window, more appears at the bottom of the window and pressing the space bar displays the next segment. Submitted commands are listed in the Review window on the left. Clicking a command from Review pastes it into the command entry window, allowing easy reuse of commands. Variables associated with the data set currently in use are listed alphabetically in the Variables window on the right. Clicking a variable name also pastes it to the command window. Variable and data set properties can be viewed in the Properties window on the right.


A Stata(console) session is shown below. The input prompt appears as a . (dot) at the bottom of the window. Commands are typed at the prompt and immediately executed after the Enter key is pressed. Results display below the command and a new prompt appears.


5. Getting Help

Stata provides a comprehensive help system, with links to internal help documents organized as mini-manuals on specific commands or topics. Keyword searches also provide links to Internet resources maintained by StataCorp and other major players in the Stata community.

Keyword searching through the Stata(GUI) entails these steps:

  1. Through the menus, select Help > Search....

  2. The subsequent Keyword Search box allows a search of official documentation help resources, net resources or both. Specify the scope of your search and enter one or more search keywords.

  3. Search results are presented in a Stata Viewer window. Browse through and explore links to items of interest. These may link in turn to other documents. If having multiple help documents open is useful, right-click on a link to display an option to Open Link in New Viewer.

  4. Use the Back button to return to the original search results or prior documents.

  5. Help results for some commands also provide dialog links in the upper, right corner that allow a menu-driven command entry. The command formed through dialog use displays in the Command window. This streamlines the process of learning command syntax.

For those wanting to peruse manuals, these are accessed online through the Help > PDF Documentation menu option, which allows access to the complete multi-volume Stata 12 documentation via an Adobe Reader.

6. Session Logs

Stata sessions (program statements and output) from the Results window are saved to a file by turning on a log. To start a log, click the Log button in the Stata(GUI) and name the log file when prompted. Any work of importance should be logged and careful thought given to naming of log files.

Logs named without a file extension are given .smcl. This designates the default Stata Markup and Control Language format in which logs are saved. Standard SMCL logs give formatted print output.

Logs may also be saved in ASCII text format with a log session command. The example below starts the log file eval_step1.txt in ASCII format, as controlled by the text option placed at the end of the command.

Logging is ended by one of the following:

Logs are viewed and printed from the Stata Viewer. To open the viewer, select File > Log > View... If a log is currently open, it will be displayed in the viewer. Otherwise you are prompted for the name of the log to view or may browse to it.

A viewer can also be opened with a view command, as illustrated below.

7. Setting Default Network Printer

Stata logs from a viewer window or graphs from a graph window are usually printed to a department network printer. Set the default printer by entering one of the following commands before printing.


Printer Selected


Computer Lab printer (Room 135)


Copy Room printer (Room 258)


Main Office color printer (Room 268)

8. Printing

The most typical method of printing is to right click in the viewer or graph window of interest and select the Print... option. A print dialog appears with many options for controlling the output format. Output goes to the network printer you designated above.

There are also command methods of printing. To print the entire contents of the Stata Results window, use:

To print a currently open Graph window, specify:

9. Submitting Jobs in Batch Mode

When running lengthy do-files, it is often better to submit in batch mode. Batch mode allows you to submit the job from the Linux command line, log off and return later to check the output from a log file. The job will run as a background process in Linux.

Assuming a do-file named, to submit this job in batch mode from the command line, one would type:

$ nohup stata-se -b do bootstrap &

This command submits for execution with all screen output suppressed. The job runs in the background and the nohup option allows you to disconnect your terminal session without terminating the background Stata process. The -b option causes the output of do-file execution to be routed to the text file bootstrap.log in the same directory as

If you wish output in smcl format, replace the -b option with -s.

You may check on the status of the job later by logging back on and running the top command to see if your process is still running. To check on the progress of a still running do-file, open the log file with the less pager command and scroll through it with the space bar.

$ less bootstrap.log

To see just the last 10 lines, use the tail command.

$ tail bootstrap.log

To see a specified number of lines, include the -n option.

$ tail -n 30 bootstrap.log

To follow a log file as it grows, use the -f option.

$ tail -f bootstrap.log

Computing Home | Sociology Home | Arts & Sciences Home | Duke Home