Skip to content

Stata

This example runs a Stata script as a job.

Code

Stata script

Let's start with a Stata script

stata-example.do
// test computation - testing.do
clear*
set rmsg on
set obs 100000
local p : env SLURM_CPUS_PER_TASK
set processors $p
forval n = 1/5 {
    g i`n' = runiform()
}
g dv = rbinomial(1,.3)
memory
qui logit dv i*
qui xtmixed dv i*
*with bootstrap:
qui bs, reps(2000): logit dv i*

Job script

Now let's create a Slurm job script to run our Stata script on one node using 48 cpus, 128Gb of RAM, and a wall time of 4 hours.

stata-example.sh
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=48
#SBATCH --licenses=stata:1
#SBATCH --mem=128G
#SBATCH --account={your_group_account}
#SBATCH --time=4:00:00

module load stata/16

# set the Stata temporary directory to the job-specific temporary directory
# this directory will be automatically deleted at the end of the job
export STATATMP=$TMP
stata-mp -b do stata-example.do

Run

We can now submit the job using sbatch:

[juser@picotte001]$ sbatch teststata.sh