Stata command line arguments in batch mode

孤人 提交于 2019-12-21 05:06:50

问题


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?)


回答1:


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.



来源:https://stackoverflow.com/questions/17253890/stata-command-line-arguments-in-batch-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!