Stata

From FarmShare

Revision as of 20:09, 2 February 2016 by Chekh (Talk | contribs)
Jump to: navigation, search

We now have Stata version 13 installed. Try the commands 'module avail', 'module load statase':

$ module help statase


-------------------- Module Specific Help for "statase/13" ---------------------
This is Stata/SE version 13

        xstata-se           (Run windowed version of Stata/SE)
        stata-se            (Run console  version of Stata/SE)

We actually have three versions installed. If you run 'stata', you get Stata/IC, if you run 'stata-se', you get 'Stata/SE', if you 'module load statamp && stata-mp', you get Stata/MP.

batch mode

Running stata in batch mode in general, use the '-b do' parameter.

Running stata in batch mode on the barley via qsub.

[chekh@corn-image-new.stanford.edu] /mnt/glusterfs/chekh [0] 
$ cat test.do 
clear
sysuse auto
describe
[chekh@corn-image-new.stanford.edu] /mnt/glusterfs/chekh [0] 
$ echo "stata -b do test2.do" | qsub -cwd -l hostname=barley05 
Your job 5725 ("STDIN") has been submitted
[chekh@corn-image-new.stanford.edu] /mnt/glusterfs/chekh [0] 
$ ls -ltr |tail -n 4
-rw-r--r-- 1 chekh root      27 Nov  7 17:27 test2.do
-rw-r--r-- 1 chekh root       0 Nov  7 17:28 STDIN.o5725
-rw-r--r-- 1 chekh root       0 Nov  7 17:28 STDIN.e5725
-rw-r--r-- 1 chekh root    2400 Nov  7 17:28 test2.log

Looks like stata doesn't print anything to stdin or stderr, but does create a .log file with the same name as your .do file.


Job script:

#!/bin/bash
source /mnt/glusterfs/software/free/modules/tcl/init/bash
module load StataSE-12.1
stata -b do test

Full session:


[chekh@barley02.stanford.edu] /mnt/glusterfs/chekh [0] 
$ qsub -cwd -l mem_free=10M script2.submit 
Your job 167221 ("script2.submit") has been submitted
[chekh@barley02.stanford.edu] /mnt/glusterfs/chekh [0] 
$ qstat
job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID 
-----------------------------------------------------------------------------------------------------------------
 167221 0.00000 script2.su chekh        qw    04/27/2012 15:21:30                                    1        
...
...
[chekh@barley02.stanford.edu] /mnt/glusterfs/chekh [0] 
$ cat test.log 

  ___  ____  ____  ____  ____ (R)
 /__    /   ____/   /   ____/
___/   /   /___/   /   /___/   12.1   Copyright 1985-2011 StataCorp LP
  Statistics/Data Analysis            StataCorp
                                      4905 Lakeway Drive
                                      College Station, Texas 77845 USA
                                      800-STATA-PC        http://www.stata.com
                                      979-696-4600        stata@stata.com
                                      979-696-4601 (fax)

23-user Stata network perpetual license:
       Serial number:  40120564988
         Licensed to:  Jane Tansuwan
                       Stanford University

Notes:
      1.  Command line editing disabled
      2.  Stata running in batch mode

Note:  Your site can add messages to the introduction by editing the file
       stata.msg in the directory where Stata is installed.

. do test 

. clear

. sysuse auto
(1978 Automobile Data)

. describe

Contains data from /mnt/glusterfs/software/non-free/stata-se-12/ado/base/a/auto
> .dta
  obs:            74                          1978 Automobile Data
 vars:            12                          13 Apr 2011 17:45
 size:         3,182                          (_dta has notes)
-------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
make            str18  %-18s                  Make and Model
price           int    %8.0gc                 Price
mpg             int    %8.0g                  Mileage (mpg)
rep78           int    %8.0g                  Repair Record 1978
headroom        float  %6.1f                  Headroom (in.)
trunk           int    %8.0g                  Trunk space (cu. ft.)
weight          int    %8.0gc                 Weight (lbs.)
length          int    %8.0g                  Length (in.)
turn            int    %8.0g                  Turn Circle (ft.)
displacement    int    %8.0g                  Displacement (cu. in.)
gear_ratio      float  %6.2f                  Gear Ratio
foreign         byte   %8.0g       origin     Car type
-------------------------------------------------------------------------------
Sorted by:  foreign

. 
end of do-file

stata-mp test

 cd /mnt/glusterfs/chekh/stata-mp-test

My test.do :

clear
sysuse auto
describe

My job.script:

#!/bin/bash
# use the current directory
#$ -cwd
# mail this address
#$ -M chekh@stanford.edu
# send mail on begin, end, suspend
#$ -m bes
# copy current env vars to job
#$ -V
stata-mp -b do test.do 

The job script uses '-V' to copy the env vars from your current session, so need to load the right module first:

[chekh@corn13.stanford.edu] /mnt/glusterfs/chekh/stata-mp-test [0] 
$ module load StataMP-12.1
[chekh@corn13.stanford.edu] /mnt/glusterfs/chekh/stata-mp-test [0] 
$ which stata-mp
/mnt/glusterfs/software/non-free/stata-mp-12/stata-mp

Test that the command works outside of grid engine:

 stata-mp -b do test.do

It produces a test.log as expected.

Submit the job:

[chekh@corn13.stanford.edu] /mnt/glusterfs/chekh/stata-mp-test [0] 
$ qsub job.script 
Your job 416828 ("job.script") has been submitted

The job is sitting there a long time because the cluster is busy and there are no immediately open slots:

$ qstat 
job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID 
-----------------------------------------------------------------------------------------------------------------
 416828 0.37250 job.script chekh        qw    09/04/2012 17:04:24              

Submit to the test queue instead:

 qsub -l testq=1 job.script

It runs immediately and produces the expected test.log file.

[chekh@corn13.stanford.edu] /mnt/glusterfs/chekh/stata-mp-test [0] 
$ ls -ltr
total 16
-rw-r--r-- 1 chekh root   27 Sep  4 16:59 test.do
-rw-r--r-- 1 chekh root  199 Sep  4 17:00 job.script
-rw-r--r-- 1 chekh root 2434 Sep  4 17:02 test.log.orig
-rw-r--r-- 1 chekh root    0 Sep  4 17:06 job.script.o416829
-rw-r--r-- 1 chekh root    0 Sep  4 17:06 job.script.e416829
-rw-r--r-- 1 chekh root 2434 Sep  4 17:06 test.log


troubleshooting

We've had a report of a user having trouble with Stata v14 and they fixed it by modifying their file:

 ~/.stata14/console/stata14.rc

So double-check your Stata settings files. Probably an easy thing to do is just to delete your .stata14 directory and start fresh, or you can compare to your ~/.stata13/console/stata13.rc

Personal tools
Toolbox
LANGUAGES