Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: Behaviour of -tokenize- shouldn't it drop the parsing character?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Behaviour of -tokenize- shouldn't it drop the parsing character?
Date   Thu, 5 Oct 2006 11:02:53 +0100

-tknz- from SSC puts a specified stub in front of 
the default names 1, 2, 3, etc. Thus you can 
tokenize into macros foo1, foo2, foo3, etc. 

This is occasionally useful when you want
to work with the results of -tokenize- 
and also another set of numbered macros. 

Nick 
n.j.cox@durham.ac.uk 

David Elliott
 
> The example I gave didn't work properly - you can't tokenize after a
> tokenize without destroying the original set of positional macros you
> were looping over.  The following better illustrates what I was trying
> to do:
> 
> local test 1 2 3 | 4 5 6| 7 8 | 9
> tokenize `"`test'"' , parse("|")
> local i = 1
> while "``i''" != "" {
> 	local group`i' = "``i''"
> 	local ++i
>    macro shift  // this advances over the token and allows i 
> to progress 1,2,3
>    }
>    local m = `i' - 1
>    local i = 1
> forvalues i = 1/`m'  {
>    tokenize `group`i''
>    local j = 1
>    while "``j''" != "" {
>        di "Group i=`i' is: `group`i'' and subitem j=`j' is: ``j''"
>        local ++j
>        }
>    local ++i
>    }
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index