Stata Listers:
I have a general question about where to specify temporary names for local macros inside ado files.
I use Stata version 15.1 and it is fully updated.
For temporary variables in Ado files, Baum gives the very helpful advice (in his book I believe) that the tempvar command can be used anywhere in an ado file, and you can list all the temporary variables that are going to be created in one place.
Does the same rule apply for the temporary names that are applied to local macros inside the Ado file?
Does the tempname command have to come right after the local it refers to is created?
In many of my Ado files, I have the "tempname" command on numerous lines, and they make my program harder to navigate. If I could consolidate them, it would shorten my programs significantly and would help me make fewer mistakes.
I also just want to make sure the local macros inside the Ado file aren't interfering with local macros outside the Ado file if they happen to share the same name.
An admittedly minor issue is the following. When you put the tempname (or tempvar) command inside a loop, as in the following example, a buildup of local macros that might slow computing in an extreme case occurs.
foreach examplelocal of local examplelocal2 {
tempname `examplelocal'
gen `examplelocal'=5
}
Specifying "tempvar" inside a loop resulted in enough temporary variables to cause Stata to stop running, when I didn't know you could specify all the temporary variables at once (and therefore outside the loop).
The bottom line is I just don't like the local macros building up.
Generally, what are best practices for where the "tempname" command should be placed in Ado files?
I've experimented with this and have looked through the documentation, but would still value guidance from experienced Stata users.
Thanks,
Carl
0 Response to Where to Specify Temporary Names for Local Macros Inside Ado Files
Post a Comment