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

Re: st: Re: problem with -capture drop-


From   [email protected] (Jeff Pitblado, Stata Corp.)
To   [email protected]
Subject   Re: st: Re: problem with -capture drop-
Date   Tue, 21 Oct 2003 16:36:12 -0500

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/



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