Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Jakob Petersen <jpeterb@essex.ac.uk> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: RE: RE: RE: macro list limits strpos |
Date | Fri, 20 Jan 2012 14:12:19 +0000 |
The extended macro function `: list ...' did the trick. Thanks a lot. Jakob On 20/01/2012 13:26, Nick Cox wrote:
Conversely, this example shows another use of -findname- (SJ): . sysuse auto, clear (1978 Automobile Data) . findname , type(int string) not headroom gear_ratio foreign That is, the last line shows variables which are not _either_ int _or_ string (or neither int not string). The equivalent with -ds- (official Stata) is . ds , not(type int string) headroom gear_ratio foreign but -ds- does not support a -local()- option; you'd need to pick its up results from `r(varlist)'. Nick n.j.cox@durham.ac.uk -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 20 January 2012 11:23 To: 'statalist@hsphsun2.harvard.edu' Subject: st: RE: RE: macro list limits strpos Also, -findname- is unnecessary for the latter part of the code. You could just loop over the variables, look up the -type- of each and display messages accordingly. No string processing is needed. Nick n.j.cox@durham.ac.uk -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 20 January 2012 10:58 To: 'statalist@hsphsun2.harvard.edu' Subject: st: RE: macro list limits strpos -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 n.j.cox@durham.ac.uk -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Jakob Petersen Sent: 20 January 2012 10:30 To: statalist@hsphsun2.harvard.edu 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/
-- Kind regards, Jakob /* Jakob Petersen Institute for Social and Economic Research (ISER) University of Essex, Colchester, Essex CO4 3SQ, UK T: +44 (01206) 873683 E: jpeterb@essex.ac.uk www.iser.essex.ac.uk Understanding Society User Support http://data.understandingsociety.org.uk/documentation/support */ * * 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/