Skip to content

Stata

Stata is a general purpose statistical software package, that provides data management, statistical analysis, graphics, simulations, regression, and custom programming.

Stata is available as a module on Apocrita.

Usage

To run the default installed version of Stata, simply load the stata module:

$ module load stata
$ stata-mp -h
stata-mp:  usage:  stata-mp [-h -q -s -b] ["stata command"]
        where:
             -h      show this display
             -q      suppress logo, initialization messages
             -s      "batch" mode creating .smcl log
             -b      "batch" mode creating .log file

Core Usage

To ensure that Stata uses the correct number of cores, the set processors command should be used. e.g.

$ stata-mp
. set processors 4

Licensing

Stata 13

The Stata/MP perpetual licence on Apocrita for Stata 13 allows for up to 8 cores per process and 6 concurrent users.

Stata 15

The Stata/MP perpetual licence on Apocrita for Stata 15 allows for up to 16 cores per process and 11 concurrent users.

Stata 18

The Stata/MP provisional licence on Apocrita for Stata 18 allows for up to 16 cores per process and 6 concurrent users.

Example jobs

Interactive jobs

Interactive mode can be useful for diagnosing issues with your Stata code.

Stata 13 Interactive Example

Run qlogin then load the module and run the binary:

$ qlogin
$ module load stata/13
$ stata-mp
. set processors 1

Stata 15 Interactive Example

Run qlogin then load the module and run the binary:

$ qlogin
$ module load stata/15
$ stata-mp
. set processors 1

Stata 18 Interactive Example

Run qlogin then load the module and run the binary:

$ qlogin
$ module load stata/18
$ stata-mp
. set processors 1

Serial job (batch mode)

Batch mode preferred

HPC clusters are designed to run queued jobs via the command line, which is the preferred method of execution over Interactive jobs.

Stata 13 Batch Example

Here is a Stata 13 example job running on 4 cores and 4GB of total memory:

#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 4
#$ -l h_vmem=1G
#$ -l h_rt=1:0:0

module load stata/13

# Run the Stata code example.do
stata-mp -b do example.do ${NSLOTS}

Stata 15 Batch Example

Here is a Stata 15 example job running on 4 cores and 4GB of total memory:

#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 4
#$ -l h_vmem=1G
#$ -l h_rt=1:0:0

module load stata/15

# Run the Stata code example.do
stata-mp -b do example.do ${NSLOTS}

Stata 18 Batch Example

Here is a Stata 18 example job running on 4 cores and 4GB of total memory:

#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 4
#$ -l h_vmem=1G
#$ -l h_rt=1:0:0

module load stata/18

# Run the Stata code example.do
stata-mp -b do example.do ${NSLOTS}

Example Input File

A sample example.do file, using data from the Stata 15 release (also works in Stata 13):

args ncores
set processors `ncores'

use https://www.stata-press.com/data/r15/census5.dta
tabulate region
summarize marriage_rate divorce_rate median_age if state!="Nevada"

Using variables in Stata

Note that ncores and other Stata variables are preceded by a single back tick ` and appended by a single quote '.

Custom Stata commands using "ado" files

Users can extend the Stata programming language by writing custom commands. These are saved as ado files. Stata checks the ado files when a non-system Stata command is executed.

Use the sysdir command to list where Stata searches for ado files. On Apocrita, the PERSONAL directory is expected at ~/ado/personal/, which needs to exist. If the directory does not exist, execute:

mkdir -p ~/ado/personal

You can then save your "ado" files in that folder and Stata should be able to find them.

Reference