Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: Using macros and batch running.

From   "Adrian Sayers" <>
To   <>
Subject   RE: st: RE: Using macros and batch running.
Date   Mon, 4 Jul 2011 15:20:51 +0100

Hi All, 

Not that i really twigged what jesper was saying until i saw another recent
post (thanks Nick Cox).

I have it sussed, with a small moment of joy...

*Create you simulation in a do file called
clear all
set obs 1000
gen id = _n
gen x = `1'*uniform()
gen y = `2'
save testdata`1' , replace

*Use the winexec program. You can pass arguments to do files by listing them
one after another, after the do file.
forvalues i = 1/3 {
local y= `i'*2*2
winexec "\\\stata11\StataMP.exe" -e do  `i'

.	Checking that it works.
forvalues i = 1/3 {
use testdata`i' , clear
su x
su y

This should make life very much quicker..

Many thanks for everyone comments.



-----Original Message-----
From: Adrian Sayers [] 
Sent: 04 July 2011 12:17
To: ''
Subject: st: RE: Using macros and batch running.

Hi Daniel,

I had thought of righting a header file. (i.e. .doh) but i am not sure this
will solve my problem. I should probably explain what i am trying to do

Currently i am running series of simulations, which take 3+ days to complete
on my PC.

Most of the process are serial, therefore their is limited gains in
parrelisation. However i had hoped that i could invoke stata in numerous
windows, this would allow me to perform all experiments in the simulation
simultaneously, drastically cutting the running time from 3 days to 20

To do this i need to modify do files on the fly, so to speak. Typically if
you were running this on only 1 machine i would bundle this in a loop and
just wait for it to run serially. 

My second attempt is to write a do file, which in turns writes all my other
do files. 

But this is not pretty, or very elegant. 
Hopefully this will give you a better idea of what i am trying to achieve.


* Create the do files in code... Basically Prefixing all code with display
foreach i in 1  2 3 {
cap log close
qui log using test`i'.do  , text replace
di "clear all                         "
di "set obs 1000                      "
di "gen id = _n                       "
di "gen x = `i'*uniform()             "
di "save testdata`i' , replace        "

qui log close

* execute batch created do files using the batch function.
forvalues i = 1/3 {
winexec "\\mypath\stata11\StataMP.exe" -e include test`i'.do


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index