Dear Statalist,
I know that do-files, like programs and ado-files, can accept simple arguments. For example, if I write a do-file showArgs.do
when I call the do-file
do showArgs.do 1 2
the output will be
value of argument a is 1
value of argument b is 2
Programs and ado-files can use more sophisticated syntax with named arguments, optional arguments, default values, allowed argument types, etc.
Is this also possible for do-files?
The reason I am asking: I am sending several batch jobs to a shared cluster. Each job is a different version of a simulation, for example with different values of the sample size num_obs and the number of repetitions num_reps. Because of the way the cluster queuing system works, my best option is to submit several different batch jobs, each calling the do file with different values of num_obs and num_reps. (That is, rather than submit one batch job with a "master" do-file that loops over values of num_obs and num_reps.)
I know that I could add simple args to my do-file, i.e.,
args num_obs num_reps
and then write the batch job as
stata -b do simulation.do 100 1000
However, to make the code clearer and more mistake-proof, I would like to imitate what I would do in an ado-file, i.e., define a syntax
syntax, num_obs(integer) num_reps(integer)
and then call the batch job as
stata -b do simulation.do, num_obs(100) num_reps(1000)
Is this allowed? Are there statalisters who have experience with this?
Alternatively, is there a better strategy I should be using instead?
I realize that I could convert simulation.do to an ado-file, say runSimulation.ado, and then call this program from several different do-files specifying different values of the parameters, e.g.
simulation1.do:
simulation2.do:
and then submit separate batch jobs calling simulation1.do and simulation2.do, but that seems unnecessarily complicated relative to just specifying the arguments directly in the batch job.
I know that do-files, like programs and ado-files, can accept simple arguments. For example, if I write a do-file showArgs.do
Code:
args a b di "value of argument a is `a'" di "value of argument b is `b'" exit
do showArgs.do 1 2
the output will be
value of argument a is 1
value of argument b is 2
Programs and ado-files can use more sophisticated syntax with named arguments, optional arguments, default values, allowed argument types, etc.
Is this also possible for do-files?
The reason I am asking: I am sending several batch jobs to a shared cluster. Each job is a different version of a simulation, for example with different values of the sample size num_obs and the number of repetitions num_reps. Because of the way the cluster queuing system works, my best option is to submit several different batch jobs, each calling the do file with different values of num_obs and num_reps. (That is, rather than submit one batch job with a "master" do-file that loops over values of num_obs and num_reps.)
I know that I could add simple args to my do-file, i.e.,
args num_obs num_reps
and then write the batch job as
stata -b do simulation.do 100 1000
However, to make the code clearer and more mistake-proof, I would like to imitate what I would do in an ado-file, i.e., define a syntax
syntax, num_obs(integer) num_reps(integer)
and then call the batch job as
stata -b do simulation.do, num_obs(100) num_reps(1000)
Is this allowed? Are there statalisters who have experience with this?
Alternatively, is there a better strategy I should be using instead?
I realize that I could convert simulation.do to an ado-file, say runSimulation.ado, and then call this program from several different do-files specifying different values of the parameters, e.g.
simulation1.do:
Code:
runSimulation, num_obs(100) num_reps(1000)
Code:
runSimulation, num_obs(200) num_reps(1000)