批处理模式下的 Stata 命令行参数 [英] Stata command line arguments in batch mode

查看:86
本文介绍了批处理模式下的 Stata 命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stata 的有用常见问题解答 描述了参数可以传递给 do 文件.我的 do 文件如下所示:

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

根据常见问题解答,可以使用 do filename.csv result.dta 运行此脚本.当我从 Stata 中运行此命令时,一切正常.但是,该程序很长,因此我想以批处理模式运行它.Stata 有关于批处理模式的另一个常见问题解答.

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.

结合来自这些网页的信息,我在 Unix 提示符下键入以下内容:

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 启动,但因以下错误而终止:

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

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

一个小实验告诉我,当我以批处理模式运行程序时,Stata 永远不会接收到这两个参数.这个问题的解决方案是什么?(即在批处理模式下运行时如何将参数传递给 do 文件?)

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

推荐答案

下面的帖子可能会有所帮助:

The thread below may be helpful:

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

在 Windows 中,如果我的程序 Test.do 是:

In Windows, if my program Test.do is:

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

我可以在 Windows 中以批处理模式运行它,只需键入:

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

"c:Stata13stata.exe"/e do "c:ScriptsTest.do" 测试脚本

它会显示(在Stata中):

And it will display (within Stata):

测试

脚本

所以我想知道 nohup 是否是阻止您的程序工作的原因.

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

这篇关于批处理模式下的 Stata 命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆