Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: do-files as programs


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: do-files as programs
Date   Thu, 25 Sep 2008 18:52:58 +0200

-set rmsg on- or -h profiler- to be sure. Once the -program- has been read
once, Stata holds it in memory (-pr dir- to see that) so I do not find this
surprising at all...


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Gabi Huiber
Sent: Thursday, September 25, 2008 6:48 PM
To: [email protected]
Subject: st: do-files as programs

I am comparing two ways to solve the same problem and I can't see why
one of them runs more quickly, but it looks that way. Is there any
reason why do-files declared as programs might run faster?

Suppose you have a do-file call another a few times, inside a loop, like so:

_____ example 1 starts here

// this is my main file

forvalues i=1/`numberoftimes' {

[declare some parameters as globals]

do mysubfile.do                    // uses the set of parameters declared
above
}
_____ example 1 ends here

In example 1, mysubfile.do is just a sequence of Stata commands. Now
suppose that you edit mysubfile.do with these lines
___

capture prog drop mySubfile
prog def mySubfile

[content of old mysubfile.do goes here]

end
___

This will then require that you run the code in example 1 as follows:

_____ example 2 starts here

// this is my main file

do mysubfile.do

forvalues i=1/`numberoftimes' {

[declare some parameters as globals]

mySubfile                    // uses the set of parameters declared above
}
_____ example 2 ends here

It seems to me that example 2, while slightly more work to write up,
runs noticeably faster. Am I imagining things?

Thank you,

Gabi
*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index