A colleague and I are undertaking Monte-Carlo simulation analysis to assess and compare the performance in terms of size of 4 different variance estimators for a form of difference in means test. The simulation code is necessarily bespoke –- we are not using -simulate- -- and output is accumulated at each MC repetition using -post- and its siblings. We need to run 10,000 MC replications.
Issue: the code is fast until it hits around 3,000 to 4,000 replications, and then slows down markedly.
Question: Any tips please regarding why this slowdown occurs? And how it can be avoided?
We don’t think the issue related to the size of the postfile. One comment we’ve had, from Claude AI, is that the slowdown is due to the accumulation of entries in Stata's tempvar and tempfile macro “registry”. (I don't think Stata has a specific macro registry; presumably it's referring to current working memory. We have large amounts available - Stata 19/MP with ~64Mb RAM.) The argument was that even though names are cleared, the registry grows indefinitely: each new tempvar checks against all previous names to ensure uniqueness, causing slowdown." We don’t know how to check the veracity of this remark -- any comments? . -help limits- doesn’t provide information to indicate that there are limits of the kind suggested.
One of the options suggested to address the problem was to use -file write- instead of -post-. We've not heard of this before and wonder if others have used it. Also, is it likely that -frame post- would address the problem? (Perhaps not if the fundamental problem is to do with the accumulation of entries in the macro registry.)
Issue: the code is fast until it hits around 3,000 to 4,000 replications, and then slows down markedly.
Question: Any tips please regarding why this slowdown occurs? And how it can be avoided?
We don’t think the issue related to the size of the postfile. One comment we’ve had, from Claude AI, is that the slowdown is due to the accumulation of entries in Stata's tempvar and tempfile macro “registry”. (I don't think Stata has a specific macro registry; presumably it's referring to current working memory. We have large amounts available - Stata 19/MP with ~64Mb RAM.) The argument was that even though names are cleared, the registry grows indefinitely: each new tempvar checks against all previous names to ensure uniqueness, causing slowdown." We don’t know how to check the veracity of this remark -- any comments? . -help limits- doesn’t provide information to indicate that there are limits of the kind suggested.
One of the options suggested to address the problem was to use -file write- instead of -post-. We've not heard of this before and wonder if others have used it. Also, is it likely that -frame post- would address the problem? (Perhaps not if the fundamental problem is to do with the accumulation of entries in the macro registry.)

Comment