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/