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: Show Command Output in Foreach Loop ...
From
Michael Stewart <[email protected]>
To
statalist <[email protected]>
Subject
Re: st: Show Command Output in Foreach Loop ...
Date
Fri, 5 Jul 2013 03:51:46 -0400
Thanks a lot Sergiy.The answer was helpful .
Mike
On Fri, Jul 5, 2013 at 12:49 AM, Sergiy Radyakin <[email protected]> wrote:
> Mike,
> you will find the answer to your first question here:
> http://www.stata.com/help.cgi?quotes
>
> For the second question the answer is that `cmd' is just the value of
> macro cmd. You can substitute the letters cmd with xyz or abc, you
> will get the same result. It does not have to be a regression.
> Furthermore it does not have to be displayed with -display-. This is
> just to say "I have a command that Stata is about to execute, is there
> anything else useful I want to do with it before or after Stata
> actually executes it?"
>
> Hope this helps, Sergiy
>
> On Thu, Jul 4, 2013 at 10:54 PM, Michael Stewart
> <[email protected]> wrote:
>> Hi,
>>
>> I am trying to understand the code written by Sergiy.I have couple of
>> questions .I hope someone can answer them.Thank you in advance for
>> your time and consideration.Sorry, they might be basic questions for
>> the expert programmers in this forum.
>>
>>
>> sysuse auto,clear
>> levelsof rep78, local(levs)
>> foreach lev in `levs' {
>> local cmd `"regress price weight if rep78==`lev'"'
>> display `"`cmd'"'
>> `cmd'
>> }
>>
>> Question-1:
>>
>> Does it matter if we substitute local cmd regress price weight if
>> rep78==`lev' for local cmd `"regress price weight if
>> rep78==`lev'"'
>>
>> I am getting the same result or am I missing something
>>
>> Likewise I am getting same result with display `"`cmd'"' OR display
>> "`cmd'".Is there any difference between the two or am I missing
>> something
>>
>>
>> Question-2:
>>
>> How does the command `cmd' work.It seems to be display the regression output
>>
>> Thanks a lot for your time.
>>
>> --
>> Yours Sincerely,
>> Mike.
>>
>> On Mon, Jul 1, 2013 at 2:07 AM, Sergiy Radyakin <[email protected]> wrote:
>>> Matthew, it has been an observation in this list that you get a much
>>> higher chances of getting responses and faster responses if you
>>> supplement your question with a starter like this:
>>>
>>> sysuse auto
>>> levelsof rep78, local(levs)
>>> foreach lev in `levs' {
>>> regress price weight if rep78==`lev'
>>> }
>>> ** eof
>>>
>>> Then all one has to do is a little edit to the code to get the answer you seek:
>>>
>>> sysuse auto
>>> levelsof rep78, local(levs)
>>> foreach lev in `levs' {
>>> local cmd `"regress price weight if rep78==`lev'"'
>>> display `"`cmd'"'
>>> `cmd'
>>> }
>>> ** eof
>>>
>>> Best, Sergiy
>>>
>>>
>>>
>>> On Sun, Jun 30, 2013 at 10:31 PM, Matthew McKay
>>> <[email protected]> wrote:
>>>> Statalist,
>>>>
>>>> I have seen a few earlier remarks in 2007 about showing commands during foreach loops.
>>>> Option 1:
>>>> Set trace on
>>>> Set tracedepth 1
>>>> This doesn't work that well for me as it clumps the commands together and then the regression output together.
>>>>
>>>> Since then, is there a better way to show the issued command during a foreach loop?
>>>> Why can't it just simply show the executed lines and the regression as if the code was running outside of a foreach loop in one long sequence?
>>>>
>>>> I have multiple datasets that I would like to run the same extensive set of analysis on.
>>>> The smcl log file output is not very reader friendly without the command breaks printed in between each regression.
>>>>
>>>> Cheers,
>>>> Matthew
>>>> Phd Student
>>>> ACDE, Crawford School
>>>>
>>>>
>>>> *
>>>> * 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/
--
Thank you ,
Yours Sincerely,
Mike.
*
* 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/