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]

Re: st: local and loops


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: local and loops
Date   Tue, 20 Aug 2013 20:05:19 +0100

How many spaces are there between "1" and "2"?

Without " " as delimiters, Stata trims internal spaces to single
spaces in local macro definition. The " " insist on taking things
quite literally.

Try

local foo a                  b                  c

and see what happens.

So, -strpos()- can't find a double space as there isn't one.

I don't think looping is germane here.

Nick
[email protected]


On 20 August 2013 19:52, Matthew White <[email protected]> wrote:
> Hi all,
>
> Using Stata 13 for Windows 7, I'm trying to figure out an interaction
> between -local- and loops. Normally when I define a local, multiple,
> consecutive internal spaces are preserved. For example:
>
> . local x 1  2
>
> . display strpos("`x'", "  ")
> 2
>
> Yet when I use the same definition in a loop, the internal spaces are trimmed:
>
> . forvalues i = 1/5 {
>   2. local x 1  2
>   3. }
>
> . display strpos("`x'", "  ")
> 0
>
> Have others experienced this before? It's probably rare that this
> would bite, but I'm running into such a situation now. Enclosing the
> contents of the local by double quotes solves the problem:
>
> . forvalues i = 1/5 {
>   2. local x "1  2"
>   3. }
>
> . display strpos("`x'", "  ")
> 2
>
> I'm just so used to dropping these quotes when I don't need them!
>
> Thank you,
> Matt
>
> --
> Matthew White
> Senior Project Associate
> Innovations for Poverty Action
> 101 Whitney Avenue, New Haven, CT 06510 USA
> www.poverty-action.org
> *
> *   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/


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