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/