Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: filter by value labels
From
Austin Nichols <[email protected]>
To
[email protected]
Subject
Re: st: filter by value labels
Date
Thu, 31 Mar 2011 16:31:33 -0400
Daniel Klein <[email protected]> et al.:
On further reflection, the last one used an incorrect and/or combo.
Also, for various reasons, one might not want the list of matching
observations, just a qualifier to apply to another command, so it
makes sense to return it.
prog drop _all
prog labmatch, rclass
version 11.1
syntax anything [, noList]
loc c "if "
forval j = 1(2)`: word count `anything'' {
loc v: word `j' of `anything'
loc vs `vs' `v'
loc m: word `=`j'+1' of `0'
mata:st_vlload("`:val lab `v''",v=.,t=.)
mata:st_local("s",invtokens(strofreal(select(v,strmatch(t,"`m'"):>0)')))
tokenize `s'
if real("`1'")<. {
if `"`c'"'!="if " loc c `c'&
if `"`2'"'=="" {
loc c `c'(`v'==`1')
}
else {
loc c `c'(
loc n 1
while `"`1'"'!="" {
if `n++'==1 loc c `c'(`v'==`1')
else loc c `c'|(`v'==`1')
mac sh
}
loc c `c')
}
}
}
if `"`c'"'=="if " loc c
if `"`c'"'!=""&"`list'"=="" l `vs' `c'
return local cond `c'
end
sysuse nlsw88, clear
labmatch race other married marr* collgrad col* occ Sal*
ret li
labmatch race other married marr* collgrad col* occ Sal*, nolist
ret li
labmatch race other married marr* collgrad col* occ "Sal*", nolist
ret li
labmatch race other married marr* occ *ers
ret li
*
* 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/