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: Fwd: Retrieving macros defined inside for loop


From   Fernando Rios Avila <[email protected]>
To   [email protected]
Subject   Re: st: Fwd: Retrieving macros defined inside for loop
Date   Tue, 19 Nov 2013 18:51:56 -0500

Sorry! I thought i change it before i click on submit.
Below is the code.
forval i = 0/6 {
local j = `i'+1
lincom star`j' - star`i'
matrix  b=nullmat(b)\[r(estimate),r(se)]
}
matrix list b

On Tue, Nov 19, 2013 at 5:36 PM, Laura Grant <[email protected]> wrote:
> That's what I thought was wrong and a great workaround. Thanks
> Fernando - nearly perfect, now can I put the output in separate rows
> (so that b is [6,2] rather than [1,12] in dimensions)?
>
> On Tue, Nov 19, 2013 at 3:54 PM, Fernando Rios Avila <[email protected]> wrote:
>> Hi Laura,
>> As far as i know, one of the advantages/disadvantages of "locals" is
>> that they only remain in memory while the program is running (Im
>> assuming you run the loop from a do file.
>> my suggestion is to store your results on a matrix:
>> reg y star0 star1 star2 star3 star4 star5 star6 star7 x1 x2 x3
>>
>>
>> forval i = 0/6 {
>> local j = `i'+1
>> lincom star`j' - star`i'
>> matrix  b=nullmat(b),[r(estimate),r(se)]
>> }
>> matrix list b
>>
>> Hope This helps.
>> Fernando
>>
>> On Tue, Nov 19, 2013 at 4:43 PM, Laura Grant <[email protected]> wrote:
>>> Simple question. I want to retrieve macros once outside the loop that
>>> are defined inside the loop.
>>>
>>> I do -regress- , then I have a loop to perform -lincom- t-tests
>>> comparing stored coefs
>>>
>>> reg y star0 star1 star2 star3 star4 star5 star6 star7 x1 x2 x3
>>>
>>>
>>> forval i = 0/6 {
>>> local j = `i'+1
>>> lincom star`j' - star`i'
>>> local c_`j'= r(estimate)
>>> local se_`j'=r(se)
>>>         display `c_1'
>>>
>>> }
>>>
>>> -display- works inside the loop but I cannot retrieve the c_j's and
>>> se_j's outside the loop. And I would like to output them to a
>>> table/text.
>>>
>>> Thanks for your help, Laura
>>> *
>>> *   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