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

st: Re: drop exact name only


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: drop exact name only
Date   Fri, 9 Aug 2002 12:01:37 -0600

----- Original Message -----
From: "Roger Harbord" <[email protected]>
To: <[email protected]>
Sent: Friday, August 09, 2002 9:55 AM
Subject: st: drop exact name only


> 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?
I
> need an way to prevent automatic expansion of variable names.  I'm trying
to
> avoid falling into the trap that some other programs fall into, such as
 <snip>
> What happened to xbest?? The answer is that -rndbin.ado- contains the
line:
>
> cap drop xb
>
> Which drops any variable name beginning with xb, rather than just dropping
a
> variable called exactly xb if one exists.

Actually, because your dataset only have one variable with the prefix xb it
drops the xbest variable.

If you had another variable named xbest2, for example, than the "capture
drop xb" than rndbin would not drop your variables.  I believe Stata would
issue an error such as "xb ambiguous abbreviation" which would be picked up
by the capture command and then Stata would move on.

One thing you could do is change rndbin code to:
program define rndbin2
cap drop xb_rndbin

and lines 89, 91 and 92:
gen xb_rndbin = `bn1'

noi di in bl "Variable " in ye "xb_rndbin " in bl "created."
lab var xb_rndbin "Binomial random variable"

and then save it as rndbin2.ado

Scott



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