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. For example, for a 4-core job:

$ stata-mp
. set processors 4

Licensing

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

Example jobs

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.

Interactive job

Interactive mode can be useful for diagnosing issues with your Stata code. The example below demonstrates how to run a 1-core interactive session, by running qlogin, loading a Stata module and running the stata-mp binary to launch the interactive interpreter.

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

Serial job (batch mode)

Here is an 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

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

Below shows the contents of the example.do file, which has been tested with Stata 18:

args ncores
set processors `ncores'

use https://www.stata-press.com/data/r18/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