Main navigation

Stata

STATA is a data analysis and statistical software.

How to Run Stata in Batch

How to Run Stata using the Queue Scripts

To run Stata in batch you need to create an input script with a “.do” extension, the script will contain the Stata commands you would use at the Stata interactive prompt.

The easiest way to run Stata in batch from the login node is to use the queue scripts. See Running a Batch Job for a discussion of the queue scripts and how they are used.

The following queue script is available for Stata:

stata.q

Runs stata-mp on 1-8 processors.

How to Run Stata Using UGE Commands

See Running a Batch Job for guidelines to follow to create the required UGE command file. Alternatively, you could create an UGE command file with the queue script listed above. After saving the command file, you can modify it if necessary. See Commonly-Used UGE Commands for a list of the most commonly used UGE commands.

How to Run Stata array-jobs

If you have to run a stata task multiple times using the same do file but changing, for example, a parameter within the study you can take advantage of the scheduler built-in job array capability which lets you submits such series of tasks with a single job submission.

A sample submission script (run_stata_jobarray.sh) for such array job is shown here (where in bold are elements that you may likely want to adapt to your own situation):


#### run_stata_jobarray.sh START ####
#!/bin/bash
#$ -cwd
#$ -o batch_test.joblog.$JOB_ID.$TASK_ID
#$ -j y
# Resources requested:
#$ -l h_data=1g,h_rt=300
#$ -pe shared 4
# Email address to notify
#$ -M $USER@mail
#$ -m bea
#$ -t 1-4:1

echo “”
echo “test started on: “` hostname -s `
echo “test started at: “` date `
echo “”
#
. /u/local/Modules/default/init/modules.sh
module load stata

#
# Tell stata how many processors to use
#
if [ -e ./profile.do]; then
echo “set processors 4” > profile.do
fi
cat ./profile.do
echo “”
#

echo “Task id is $SGE_TASK_ID”
echo “”

#
# Run the user program
#

cp -p ./batch_test.do ./batch_test_$SGE_TASK_ID.do
stata-mp -b do batch_test_$SGE_TASK_ID.do $SGE_TASK_ID

#### run_stata_jobarray.sh END ####

 

Should the run-time of your tasks be very short you should group set of tasks as described in: How do I pack multiple job-array tasks into one run?

To submit the run_stata_jobarray.sh script you will need to issue the following commands:


chmod u+x run_stata_jobarray.sh
qsub run_stata_jobarray.sh

 

How to Run Stata from the UCLA Grid Portal

See How to Run an Application from the UCLA Grid Portal

How to Run Stata Interactively

To run Stata interactively with its GUI interface, you must first connect to the cluster login node with X11 forwarding enabled. Then you have to request an interactive session via qrsh

To run Xstata interactively with its GUI interface, enter:

module load stata
xstata-se

Or, for the multi-processor version of Xstata, enter:

module load stata
xstata-mp

To run Stata interactively without its GUI interface, enter:

module load stata
stata-se

Or, for the multi-processor version of Stata:

module load stata
stata-mp

How to Run Stata Interactively from the UCLA Grid Portal

See How to Run an Application from the UCLA Grid Portal
 

Stata temporary directory

Stata writes temporary files to the directory /tmp or, if the $TMPDIR environmental variable is set, to the location pointed to by such variable. During a batch job the $TMPDIR is set by the scheduler and points to a temporary directory located on the hard disk on the node where the job is running.

How to change the default location of the temporary directory

Should you need to have stata write its temporary files somewhere else then in the locations indicated above you can do by defining the $STATATMP before starting your stata session. On bash/sh shells you can do so by issuing:

export STATATMP=/path/to/your/stata/tmpdir

On csh based shells:

setenv STATATMP /path/to/your/stata/tmpdir

To verify the current location of the temporary directory Stata is using you can issue at the Stata command prompt the following commands:

. tempfile junk
. display "`junk'"

 

How to read system environmental variables into Stata

System environmental variables such as the location of your scratch on the cluster ($SCRATCH), or within a batch job contest, the job ID number, $JOB_ID, or for array jobs the task ID number, $SGE_TASK_ID, can be accessed from stata via macros. For example to use $SCRACT within an interactive stata session or a stata do file:

local scratch : env SCRATCH
display "`scratch'"

and to change to $SCRACT within an interactive stata session or a stata do file:

cd `scratch'

To access either $JOB_ID or $SGE_TASK_ID from within an interactive stata session or a stata do file:

local jid : env JOB_ID
display `jid'

or:

local tid : env SGE_TASK_ID
display `tid'

 

How to install Stata user-written additions

To install in your $HOME directory and manage user-written additions from the net use the stata command net. To learn more at the stata command prompt issue:

. help net

The contributed commands from the Boston College Statistical Software Components (SSC) archive are installed in the users $HOME directory as needed. To do so start an interactive session of Stata and at its command prompt issue:

. ssc install pagkage-name

to check the location on your $HOME directory of stata packages at the stata command prompt issue:

. sysdir

to check the locally installed packages issue at the stata command prompt:

. ado

 

Report Typos and Errors
UCLA OIT

© 2016 UC REGENTS TERMS OF USE & PRIVACY POLICY