[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: newbie question on replacing variables in do file
Alan Acock wrote:
QUESTION: How can I have the gen and egen commands replace the variables
I want it to replace rather than having to first drop them???
When I run a series of commands to generate new variables in a do file and realize I made a mistake on one of them, I would like to fix the mistake, highlight the section of commands, and run the selection. When I do this, Stata says the generated variables already exist. Sooooo, I need to drop each variable I created in the series of commands, and then re-run them. I assume this is a way Stata has to prevent accidently replacing a variable.
If, in your programs, you insert the line
capture drop varname
just before the
gen varname = __function__
egen varname = __function__
then Stata will drop varname if it already exists, or do nothing if it
doesn't, and proceed with the gen or egen function you require.
Any information, including protected health information (PHI), transmitted
in this email is intended only for the person or entity to which it is
addressed and may contain information that is privileged, confidential and or
exempt from disclosure under applicable Federal or State law. Any review,
retransmission, dissemination or other use of or taking of any action in
reliance upon, protected health information (PHI) by persons or entities other
than the intended recipient is prohibited. If you received this email in error,
please contact the sender and delete the material from any computer.