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

st: RE: RE: Referring to a varname, leading to errors


From   [email protected]
To   [email protected]
Subject   st: RE: RE: Referring to a varname, leading to errors
Date   Wed, 12 Feb 2003 11:20:31 -0500

I wrote,

> Abbreviations can hurt you even if you don't ever use them,
> such as
> 
> i)  dropping a variable you never intended to drop; or
> 
> ii) inadvertently modifying the wrong variable
> 
> For e.g., at some point in time your data contains 
> variables _foo_ and _foobar_.  You no longer need _foo_
> so you -drop- it.  Later, (wrongly) believing _foo_ is
> still defined, you -replace foo = ...- but it modifies
> -foobar- instead since Stata finds no ambiguity in the 
> string literal _foo_.  You might never notice this blunder.
> Dealing with large datasets at times, with hundred of
> variables possessing names that differ by only a character
> or two, this can have unfortunate consequences.  I almost
> never use abbreviations myself either and typically, when
> I want to modify _foo_, it is _foo_ I want to change and
> certainly *not* _foobar_.

to which Nick replied,

> As mentioned in an earlier posting, safe dropping is 
> entirely controllable. The question came up on the list a few years 
> ago and I posted some code, although my guess was then 
> -- perhaps wrongly -- that it was a one-off request. 
> 
>(code omitted, see Nick's earlier email)

Very true, and a similar routine can be used to handle safe replacing, i.e.

cap prog drop safereplace
program def safereplace
*! in the spirit of safedrop.ado by N.J.Cox
*! version 1.0   12fev2003   PJoly
	version 7.0
	
	unab V : `1'
	if "`V'" != "`1'" {
		di as err "`1' incomplete variable name"
		exit 198
	}
	replace `0'
end

That said, these wrapper routines are not really the answer since any other
.ado command (whether user-written or official Stata) that drops or replaces
variables does so using -drop- and not -safedrop-.  Like Lee, I wouldn't go
as far as picketing in front of Stata headquarters but perhaps I could say
that a pragmatic module to toggle abbreviations on or off would probably
help me sleep better at night. :)


Patrick Joly
[email protected]
[email protected]
*
*   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