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: Test position of a whole word within a macro
From
"Sarah Edgington" <[email protected]>
To
<[email protected]>
Subject
st: RE: Test position of a whole word within a macro
Date
Tue, 3 Dec 2013 14:53:43 -0800
Brent,
Forgive me if I am misunderstanding what you are trying to do but it looks
like from your initial example that you are trying to count the number of
words in string.
If that is in fact what you're trying to do, you might try the function
wordcount. So you'd have something like:
local test=wordcount("var12 var3 var1")
-Sarah
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Brent McSharry
(ADHB)
Sent: Tuesday, December 03, 2013 2:36 PM
To: [email protected]
Subject: st: Test position of a whole word within a macro
Dear statalisters
I need to determine the position (in words, not characters) a word is within
a macro. For example:
local test = *wordposition*("var12 var3 var1")
local test should have a value of 3.
It will be used within a loop which will be called hundreds of times, so it
must be performat, and for this reason I will only use a foreach loop if
this is the only way.
The programming (ie not stata) solution would be to create a 'dictionary'/
hash table of the string values.
The pseudo-code for what I am trying to do () is . matrix `outmat' =
J(`indepcount', 1,0) . matrix rownames `outmat' = `indepvars'
. forvalues i=1(1)`iterations' {
. //reassign division of development and testing data sets
. //build model & exclude unwanted variables
. local included:colfullnames(e(b))
. //remove _cons from `included'
. foreach v in `included' {
. //if vectors could be referred to by string, one would use
. // `outmat'[`v'] = outmat'[`v'] + 1
. //I don't think the above is possible in stata, so instead:
. local i = //which word
. `outmat'[`i'] = outmat'[`i'] + 1
. }
. }
Does anyone have any ideas on a performant way to test for an exact word
match? Thank you
Brent McSharry
Intensivist
Starship Hospital Auckland
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/