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   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: newbie question on replacing variables in do file
Date   Sun, 15 Feb 2004 16:19:09 -0000

The short answer is No. 

The clear-cut distinction between -generate- and -replace- 
is usually a strong feature. Losing variables accidentally 
could mean the loss of a great deal of hard work. 

A master command that combines the two 
is certainly possible: see John Gleason's -defv-, for 
example. (I have a memory that this would need some 
tweaking to make it up-to-date.) 

An -ereplace- (or whatever you want to call it) is also certainly 
possible and at least one has been written. In practice it would 
be one more command to know about  without any major advantages, 
given that a quick -drop- clears a mistaken -egen- result 
out of the way. 

If a do file contains a mixture of correct and incorrect 
statements, often the best thing to do is to start afresh
with the original data until the do file is fixed. 

Another alternative is to pair statements like this: 

capture drop foo 
gen foo = ... 

Nick 
[email protected] 

Richard Williams replied to Alan Acock:

> >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 rathr than having to first drop them???
> >Alan Acock
> >[email protected]
> 
> Yes, I wish there was an option that let you throw caution to the 
> wind.  Stata protects users from themselves more than Spss does.
> 
> Instead of -gen-, use -replace-.  Type -help replace- for 
> more details.
> 
> I don't know of a similar command for -egen-.  It seems odd 
> that there 
> isn't, but maybe I am just missing it.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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