Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stata command line arguments in batch mode

A helpful FAQ from Stata describes that arguments can be passed to do files. My do file looks like this:

* program.do : Program to fetch information from main dataset
args inname outname

save `outname', emptyok // file to hold results
insheet using `inname', comma clear names case

// a bunch of processing

save `outname', replace

According to the FAQ, this script can be run using do filename.csv result.dta. When I run this command from within Stata, everything works fine. The program is long, however, so I want to run it in batch mode. Stata has another FAQ about batch mode.

Combining the information from these webpages, I type the following at my Unix prompt:

$ nohup stata -b do program.do filename.csv result.dta &

Stata starts up, but it terminates with the following error:

. save `outname', emptyok // file to hold results
invalid file specification
r(198);

A little experimentation tells me that Stata is never receiving the two arguments when I run the program in batch mode. What is the solution to this problem? (i.e. how do you pass arguments to a do file when running it in batch mode?)

like image 636
ChrisP Avatar asked Jun 22 '13 18:06

ChrisP


People also ask

How do I run a batch file in Stata?

Any do-file that you run in batch mode can also be run interactively. Simply start Stata, type log using filename, and type do filename. You can then watch the do-file run, or you can minimize Stata while the do-file is running.

How do you give command line arguments?

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.

How many mode of operations do Stata can be operated?

13.2 Operators Stata has four different classes of operators: arithmetic, string, relational, and logical.


1 Answers

The thread below may be helpful:

http://www.stata.com/statalist/archive/2012-09/msg00609.html

In Windows, if my program Test.do is:

args a b
display "`a'" 
display "`b'" 

I can run it in batch mode in Windows by simply typing:

"c:\Stata13\stata.exe" /e do "c:\Scripts\Test.do" Test Script

And it will display (within Stata):

Test

Script

So I wonder whether the nohup is what's preventing your program from working.

like image 150
Lucas A. Meyer Avatar answered Sep 21 '22 22:09

Lucas A. Meyer