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

Re: st: drop exact name only

From   Bill Rising <[email protected]>
To   "Stata Listserve" <[email protected]>
Subject   Re: st: drop exact name only
Date   Fri, 9 Aug 2002 13:06:51 -0400

On 8/9/02 11:55, Roger Harbord wrote

>How do I drop a variable a variable only if it has exactly the name I 
>specify, rather than any name that begins with the characters I specify?  

try this on for size. It's probably far too complicated.
---------------------------- cut here ----------------------------

/* strangely enough, this returns xb if there are many starting with xb */
capture unab xbfull : xb, max(1)
if _rc {
  /* either many or none, so dropping won't drop anything but a true xb */
  capture drop xb
else {
  /* one variable was returned, check that it really is xb */
  if "`xbfull'"=="xb" {
     drop xb
---------------------------- cut here ---------------------------- 
>I need an way to prevent automatic expansion of variable names.  


>I'd be grateful for advice on what's considered best Stata programming 
>practice to avoid this pitfall,

Another way around the problem is to have an error checker test to see if 
the true xb really exists before dropping it (in the way that an existing 
_merge prevents using the merge command).

I generally don't build -drop- into my ado files, unless it is dropping a 
temporary variable which it declared and must drop before saving a file.

*   For searches and help try:

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