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]

AW: st: Creating local from levelsof exceeding 255 characters


From   "Palan, Stefan ([email protected])" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   AW: st: Creating local from levelsof exceeding 255 characters
Date   Fri, 14 Jan 2011 14:45:54 +0100

Hi again,

Naturally, you are right, Maarten. I have now found the problem, but don't know how to address it.

What I do is, I fill my local "a" with the levelsof some variable. The local a then contains some 100 numbers. But then, I need to create a local that contains a string that looks like "t1 t2 t4 t7...". In other words, it needs to contain an entry for each number in a, but with a leading "t", because my variable names are t1, t2, etc. What I do is the following:

foreach v of local a {
    local b="`b' t`v'"
}

Obviously, this building-up of the local b involves an evaluation of it at each step, which then causes it to get truncated.

Can you think of a way around this problem?

Stefan.

----

From	  Maarten buis <[email protected]>
To	  [email protected]
Subject	  Re: st: Creating local from levelsof exceeding 255 characters
Date	  Fri, 14 Jan 2011 11:26:01 +0000 (GMT)

 --- On Fri, 14/1/11, Palan, Stefan wrote:
> However, the truncation problem seems to occur when I use it
> in a foreach statement. What I would like to do is loop over
> all values in my macro, but it stops after 255 characters.

That means that at some point you still evaluated that local.
As long as you do not do so, there will be no problem:

*--------------- begin example -------------------
// create a variable such that a string listing
// all its values is longer than 245 characters
drop _all
set obs 500
gen id = _n

// store that string in locals
levelsof id, local(levs)

// do the loop
foreach lev of local levs {
	di "`lev' " `newl'
}
*--------------- end example ----------------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------

*
*   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/


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