Nick wrote:
> Both Michael Blasnik and Ben Jann suggested
>
> forval i = 1/20 {
> local mac`n' = x[`n']
> }
>
> In some circumstances that could bite. Evaluating
> rather than copying could lose parts of long
> strings and/or leading blanks. A more general
> solution is
>
> forval i = 1/20 {
> local mac`n' `"`=x[`n']'"'
> }
I find it quite confusing that Nick's solution
preserves leading blanks. As I understand the
macro expansion operator (`...'), Nick's solution
should be equivalent to
forval i = 1/20 {
local x = x[`n']
local mac`n' `"`x'"'
}
but, apparently, it isn't. Can anyone explain
this to me?
Secondly, note that Nick's solution is subject
to the length limit for string expressions, too.
This length limit, however, is irrelevant in the
present case, because string variables have the
same limit.
The length limit may become relevant if several
string variables be concatenated. In this case,
it would indeed make sense to code
forval i = 1/20 {
local mac`n' `"`=x1[`n']'`=x2[`n']'"'
}
rather than
forval i = 1/20 {
local mac`n' = x1[`n'] + x2[`n']
}
ben
*
* 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/