Eddy <[email protected]> asks about dropping variables:
> Thanks for the explanation, but I still cannot fathom the logic of
> this implementation. If I want to drop a single or all variables
> begining with r, I shall use a wildcard like r*, no matter whether I
> have only one variable beginning with r in the dataset or not. If I
> want to drop the literatral "r", I shall be able to do so by
> specifying -capture drop r-.
>
> Anyway, the practical issue here is: Is there a way to stop Stata
> from playing smart in this type of situation? Thanks.
Eddy can check that the variable "r" truly exists by using the -unab- command.
For example, in Stata 8, Eddy could try:
. capture unab uv : r
. if (!c(rc) & "`uv'" == "r") drop r
Here is a short program that will loop over its arguments (variable names),
and will drop a variable if it explicitly matches a specified name.
***** BEGIN: drop2.ado
program drop2
version 8.1
while `"`0'"' != "" {
gettoken v 0 : 0
capture unab uv : `v'
if (!c(rc) & "`uv'" == "`v'") drop `v'
}
end
***** END: drop2.ado
--Jeff
[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/