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

st: RE: confirm


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: confirm
Date   Sun, 25 Sep 2005 17:23:36 +0100

This problem is a variation on 
two previously discussed on this list. 

1. You want to -drop- variables if and only 
if the names specified are full variable names. 

Canned solution: -safedrop- on SSC

2. You want to separate a set of names 
into variable names and others. (Compare a very 
recent thread.) 

Canned solution: -isvar- on SSC 

In each case, a useful trick is throw 
something at -unab-. 

If it returns an error, that something is
ambiguous or not a variable name. 

If you get back exactly what you 
sent, that something is a complete variable name. 

Otherwise it must be incomplete. Incomplete 
here includes valid wildcards. 

Here is a sketch: 

*! NJC 1.0.0 25 September 2005 
* safedrop NJC 1.1.0 11 February 2003 	
* safedrop NJC 1.0.0 13 November 2000 	
program isfullvarname, sclass  
	version 8.0 
	foreach v of local 0 { 
		capture unab V : `v' 
		if _rc local blist `blist' `v' 
		else if "`V'" == "`v'" local flist `flist' `v' 
		else local ilist `ilist' `v' 
	} 

	sreturn clear 
	di 

	local n : word count `blist' 
	if `n' {
		local what "ambiguous or non-existent" 
		di "{p}{txt}`what': {res}`blist'{p_end}" 
		sreturn local notvarlist "`blist'"
	} 
	
	local n : word count `ilist' 
	if `n' {
		local what = plural(`n',"incomplete variable name") 
		di "{p}{txt}`what': {res}`ilist'{p_end}" 
		sreturn local notfullvarlist "`ilist'"
	} 

	local n : word count `flist' 
	if `n' {
		local what = plural(`n',"full variable name") 
		di "{p}{txt}`what': {res}`flist'{p_end}" 
		sreturn local fullvarlist "`flist'"
	} 
end 



Nick 
[email protected] 

Enzo Coviello
 
> how can Stata 8 verify that a name match "exactly" the name 
> of an existing 
> variable, i.e. ignoring names that are abbreviations of other 
> variables?
> 
> "confirm varlist, exact" in Stata 9 resolves this problem, 
> but in Stata 8? 

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