Bookmark and Share

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: Test position of a whole word within a macro


From   "Brent McSharry (ADHB)" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Test position of a whole word within a macro
Date   Wed, 4 Dec 2013 11:35:41 +1300

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index