Hi all,
I have programmed almost entirely in object-oriented languages until recently beginning Stata and have some workflow practices that are not serving me well. I'm looking for some advice on how to go about writing foreach, which will also apply when I want to write stata programs.
I'm writing a foreach that creates some count variables. In the "figuring it out" phase, the foreach won't always finish due to some syntax error or similar. In R, I would trace the error, make any necessary changes, and re-run the loop. This works in R because its default behaviour is to overwrite the contents of an object when the object is reassigned.
In Stata, if I generate some vars in a foreach that doesn't finish, I need to drop all the vars that were created to that point in the foreach before I can re-run it after making changes. If I forget to drop one, it throws an error because "generate" can't be used once a particular var is already defined, and the cycle continues. How do more experienced Stata programmers work with this aspect of the language?
Kind regards,
Matt
I have programmed almost entirely in object-oriented languages until recently beginning Stata and have some workflow practices that are not serving me well. I'm looking for some advice on how to go about writing foreach, which will also apply when I want to write stata programs.
I'm writing a foreach that creates some count variables. In the "figuring it out" phase, the foreach won't always finish due to some syntax error or similar. In R, I would trace the error, make any necessary changes, and re-run the loop. This works in R because its default behaviour is to overwrite the contents of an object when the object is reassigned.
In Stata, if I generate some vars in a foreach that doesn't finish, I need to drop all the vars that were created to that point in the foreach before I can re-run it after making changes. If I forget to drop one, it throws an error because "generate" can't be used once a particular var is already defined, and the cycle continues. How do more experienced Stata programmers work with this aspect of the language?
Kind regards,
Matt
Comment