Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: surprising behaviour in -lookfor-?


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: RE: surprising behaviour in -lookfor-?
Date   Tue, 27 Jan 2009 11:56:12 -0500


David Elliott wrote:

Options like varonly or labonly would increase -lookfor-'s utility in
this context.


Here's -lookform- ("look for'em"), not sure what the convention is
for documenting code borrowed from Stata, I just put it in a footnote.

Allows the options -nolabels- and -novars-, though of course if you
put them both, you will get an error. As an added "feature" (per the
original thread here) any commas, comments marks etc must be in
double quotes to get through.


*--------------------------------------------------------------*
*! version 1.0 27jan2009
program lookform, rclass
	version 10
	syntax anything [, noLABels noVARs]


	if `"`anything'"' == "" {
		di as err "nothing to look for"
		exit 198
	}
	if "`labels'"== "nolabels" & "`vars'"=="novars" {
		di as err "nowhere to look"
		exit 198
	}

	foreach W of local anything {
		local w = lower(`"`W'"')
		local looklist `"`looklist' `"`w'"'"'
	}

	local 0 "_all"
	syntax varlist

	foreach v of local varlist {
		local lbl : variable label `v'
		local lbl : subinstr local lbl "'" "", all
		local lbl : subinstr local lbl "`" "", all
		foreach w of local looklist {
			if index(lower(`"`v'"'),`"`w'"') ///
					& "`vars'"!="novars" {
				local list "`list'`v' "
				continue, break
			}
	 		if index(lower(`"`lbl'"'),`"`w'"') ///
					&"`labels'"!="nolabels" {
				local list "`list'`v' "
				continue, break
			}
		}
	}

	if "`list'" != "" {
		describe `list'
		return local varlist `list'
	}
end
exit

1.0 adapted from -lookfor- 3.2.2
*--------------------------------------------------------------*
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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