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]
st: RE: macro list limits strpos
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: macro list limits strpos
Date
Fri, 20 Jan 2012 10:58:17 +0000
-findname- (SJ ) is a user-written program. Please remember....
Your difficulty is that -strpos()- won't find items beyond a certain position in a string because of limits on the length of string it handles. This difficulty is explained in the 2008 posting you cite and is nothing whatsoever to do with memory or maxvar settings. The maximum is 244 in all flavours of Stata (12) and is not tunable.
Try this:
sysuse auto,clear
findname,type(string) local(vstr)
findname,type(int) local(vint)
foreach v of varlist * {
if `: list v in vstr' {
di "`v' is a string variable"
}
if `: list v in vint' {
di "`v' is an integer variable"
}
if `: list v in vother' {
di "`v' is not string nor integer variable"
}
}
In fact, notice that your logic can be simplified to
sysuse auto,clear
findname,type(string) local(vstr)
findname,type(int) local(vint)
foreach v of varlist * {
if `: list v in vstr' {
di "`v' is a string variable"
}
else if `: list v in vint' {
di "`v' is an integer variable"
}
else "`v' is not string nor integer variable"
}
Nick
[email protected]
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jakob Petersen
Sent: 20 January 2012 10:30
To: [email protected]
Subject: st: macro list limits strpos
Statalist,
Problem: The following does not scale up to longer macro lists and
variables at the end of longer macros are cut off.
***************************************************
sysuse auto,clear
findname,type(string) local(vstr)
findname,type(int) local(vint)
findname,local(vother)
local vother : list vother - vstr
local vother : list vother - vint
di "`vstr'"
di "`vint'"
di "`vother'"
foreach v of varlist * {
if strpos("`vstr'","`v'") {
di "`v' is a string variable"
}
if strpos("`vint'","`v'") {
di "`v' is an integer variable"
}
if strpos("`vother'","`v'") {
di "`v' is not string nor integer variable"
}
}
***************************************************
Any ideas?
Similar to: http://www.stata.com/statalist/archive/2008-01/msg00945.html
Tried increasing maxvar to no avail - is there away of increasing mem
allocation here or is a different approach to -strpos- required?
Thanks,
Jakob Petersen
*
* 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/
*
* 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/