Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: newbie question on replacing variables in do file

From   John Hennen <>
Subject   Re: st: newbie question on replacing variables in do file
Date   Sun, 15 Feb 2004 10:30:55 -0500

Alan Acock wrote:

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.

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???
Alan Acock


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.

John Hennen

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.

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index