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: Re: Re: st: Words surrounded with single quotes in a local macro


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: Re: Re: st: Words surrounded with single quotes in a local macro
Date   Wed, 15 Jan 2014 13:48:54 +0000

<>

That's helpful. In fact, the main problem was visibly there in your
first post. I just reacted to the wrong elements, notably your rather
cryptic summary.

How to debug code like this?

1. Think through it carefully, line by line.

2. You often need to go round a loop in your head at least twice, as
sometimes problem show up the second time.

In this case, the line

local  kemp2  `kemp2'  `"`tf`i''"'

is the heart of the problem. First time round it becomes

local  kemp2  `kemp2'  `"`tf1'"'

So, Stata needs to evaluate

`tf1'

But you evidently have no local macro with that name, so Stata
substitutes an empty string. The syntax is legal, but not what you
want.

And it's the same for all times round the loop. No `tf2', etc.

P.S. Your first post appears to me as including stuff like

&#8217;

That looks like stray HTML or something similar. See
http://www.stata.com/statalist/archive/2014-01/msg00525.html

Nick
[email protected]


On 15 January 2014 13:35, Tomas Lind <[email protected]> wrote:
> Running this code:
>
> local Nkomb 8
> forvalues  i = 1/`Nkomb'  {
> local  tempo   `tempo'    tf`i'
> local  kemp2  `kemp2'  `"`tf`i''"'
> }
> *
> di "`tempo'"
> di "`kemp2'"
>
>
> Stata responds this after the two display-commands above:
>
> di "`tempo'"
> tf1 tf2 tf3 tf4 tf5 tf6 tf7 tf8      Okey
>
> di "`kemp2'"                         No output
>
> I´ve try to read the manual about double quotes but there they
> just enclose " within `"  '"
>
>
> /Tomas
>
>
>
> [email protected] skrev: -----
> Till: "[email protected]" <[email protected]>
> Från: Nick Cox
> Sänt av: [email protected]
> Datum: 2014-01-15 14:22
> Ärende: Re: Re: st: Words surrounded with single quotes in a local macro
>
> Check on
>
> temp2
>
> versus
>
> tempo2
>
> You may be using different names in different parts of your code.  In
> both of your posts you have mentioned them as if they were the same.
>
> Quite different issue: Local macros are only visible within the same
> "locale", i.e. the same interactive session, program, do-file,
> (highlighted) do-file editor contents.
>
> Nick
> [email protected]
>
>
> On 15 January 2014 13:08, Tomas Lind <[email protected]> wrote:
>> After having created locals temp and temp2 I display them.
>> The first local, temp, show the names I have excepted.
>>
>> di "`tempo'"
>> tf1 tf2 tf3 tf4 tf5 tf6 tf7 tf8
>>
>> However, Stata doesn´t return anything for temp2
>>
>> di "`tempo2'"
>>
>>
>> When Stata executes the append-statement, I get an error message:
>>
>> append using "`tempo2'"
>> file  not found
>>
>>
>> /Tomas
>>
>>
>>
>> [email protected] skrev: -----
>> Till: "[email protected]" <[email protected]>
>> Från: Nick Cox
>> Sänt av: [email protected]
>> Datum: 2014-01-15 13:52
>> Ärende: Re: st: Words surrounded with single quotes in a local macro
>>
>> You can help yourself debug this by showing us the value of `tempo2'
>> and explaining what "Do[es] NOT Work" means precisely.
>>
>> Nick
>> [email protected]
>>
>>
>> On 15 January 2014 12:30, Tomas Lind <[email protected]> wrote:
>>> Hi all,
>>>
>>> I´m setting up number of tempfiles named tf1, tf2, tf3 . . .  .
>>>
>>> First I create the names and put them into a macro called tempo.  That works fine.
>>>
>>> The problem is with the second makro, temp2, where I try to store the names `tf1&#8217;  `tf2&#8217;  `tf3&#8217; . . . enclosed in quotes to be able to use them in an append statement.
>>>
>>> I want the append statement to look like this:
>>> append `tf1' `tf2' `tf3' . . .
>>>
>>>
>>> forvalues  i = 1/`Number'  {            // This many tempfiles
>>> local  tempo   `tempo'    tf`i'    //  named  tf1, tf2, tf3 . . . okey
>>> local  tempo2  `tempo2'  `"`tf`i''"'    // `tf1&#8217;  `tf2&#8217;  `tf3&#8217; . . .  Do NOT work
>>> }
>>>
>>> tempfile `tempo'                              // works fine
>>>
>>>
>>> Loop that runs several regressions and store
>>> each result in a tempfile
>>>
>>>
>>> append using "`tempo2'"              // Do NOT work
>>>
>>>
>>>
>>>
>>> Anyone have a solution on this?
>>>
>>> I´m running Stata 13.1 on a PC
>>>
>>> Yours
>>> Tomas
>>> *
>>> *   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/
>> *
>> *   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/
> *
> *   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