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

st: -safedrop- added to SSC


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: -safedrop- added to SSC
Date   Thu, 23 Oct 2003 11:45:47 +0100

Thanks to Kit Baum, a small utility -safedrop- has been added
to SSC. 

This addresses the problem raised by eddy_05831 on 21 October, 
and in a previous thread around 12 February, and earlier 
on Statalist. Here I recapitulate the entire issue as 
I understand it, without assuming that you read and 
remembered any of those threads. 

-safedrop- drops variables if and only if their variable names are 
specified in full, i.e. abbreviation, even if unambiguous, is 
disallowed. So with a syntax of 

. safedrop <namelist> 

-safedrop- drops the variable(s) named in <namelist>
if and only if every element of <namelist> is a fully 
spelled out variable name.

To make this concrete, suppose (1) you want to drop 
variable -myvar- if and only if that variable exists with
exactly that name; (2) there is just one variable in your 
dataset whose name begins with -myvar-, namely -myvariable-.  
As -myvar- is an unambiguous abbreviation of -myvariable-, 
both 

. drop myvar 

and 

. capture drop myvar 

will cause -myvariable- to be dropped. This is not 
a bug, even if it may occasion surprise; it is just a 
consequence of Stata's variable name abbreviation rules. 

. safedrop myvar 

is a way to ensure that this does not happen.

Stata 8 is required. -ssc- may be used to install. 

Nick 
[email protected] 

P.S. David Kantor's suggestion of adding an option 
to -drop- would be a much better way to handle this, 
but is beyond the reach of user-written programs. 
*
*   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