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 <brising@louisville.edu>
To   "Stata Listserve" <statalist@hsphsun2.harvard.edu>
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.  

[snip...]

>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.

Bill
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index