Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

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


From   "Adrian Sayers" <adrian.sayers@bristol.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 test.do
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 "\\Epi-doll.epi.bris.ac.uk\stata11\StataMP.exe" -e do test.do  `i'
`y'
}


.	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.

Cheers

Adrian.



-----Original Message-----
From: Adrian Sayers [mailto:adrian.sayers@bristol.ac.uk] 
Sent: 04 July 2011 12:17
To: 'statalist@hsphsun2.harvard.edu'
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
better. 

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
minutes.

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.

Cheers
Adrian

E.g.
****************************************************************************
**
* 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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index