[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Re: controlling output in the results window |

Date |
Thu, 5 Mar 2009 18:54:17 -0000 |

Thanks for this. I can't follow the question embedded here about e(b), but I wouldn't infer any special properties necessarily. Sometimes one's misunderstandings cancel and the right answer arrives for the wrong reason. I think it's fair to say that the Mata manuals are pitched at a different level from the Stata manuals with different assumptions about the motivation and knowledge of the readership. If you don't know some programming already, learning Mata would be a tough call. That leaves enormous scope for user-friendly introductions, such as Kit's new book. Nick n.j.cox@durham.ac.uk Thomas Jacobs Thanks very much for taking the time to examine the code and provide suggested improvements. I cannot disagree with any of your comments and your code produces identical results to what I had. By way of explanation, I posted the first version I was able to get working and even then missed that rather than calling the eofb matrix I created upstream in stata for the purpose of passing to this mata function, I still had the "e(b)" matrix eofb was created from in the mata function and was surprised it still worked. So I take it there is some property of e matrices that they are still seen in an ado mata function whereas any matrices I create myself within stata have to be explicitly passed. I appreciated all of your efficiency comments, particularly the elimination of creating local macros within the ado and simply referring to the passed parameters as real scalars within the function directly as my prior attempts to do this had been unsuccessful. IMHO, the stata manuals are rather sparse and confusing regarding passing arguments to a mata function (page 13 of [M-1] ado) so again I appreciate your taking the time to modify my example. Finally, the entire purpose of this little routine was to save me time scrolling up and down in the event window around the blocks of mata code created by repeatedly implementing this within the do file directly. I only posted it in hope that if someone else ran into this they might find a working, albeit inefficient, example of passing a stata matrix to a mata function in an ado. On Sun, Mar 1, 2009 at 11:51 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > > There seems to be scope for simplifying the code here. For example, > in your calling program -scolfirm- is a local macro containing a number. > > You could just pass that to your Mata function as a real scalar. The > same goes for some other arguments. > > Also, you do the double conversion > > strtoreal(st_local("scolFirm")) > > twice, which is not necessary. > > On a different point, there are so many wired-in constants here that it > is difficult to see any gain over a few lines of a do-file. Perhaps you > are working gradually towards a more general program. > > Here is a revised (and untested) version. > > program ProduceResults > > version 10.1 > mata: OutputFn("eofb","sFirmModelResults", `1', `2', `3') > > end > > version 10.1 > mata: > void OutputFn(eofb,sFirmModelResults, real scalar Begin, real scalar > End, real scalar Firm) > { > printf("Results for Event Period beginning with trading day > %4.0f and > ending at day %4.0f.\n", Begin, End) > FirmModelVar = st_matrixcolstripe("e(b)")[.,2] > printf("Average Firm Adjusted R Square %12.4f\n", > st_matrix(sFirmModelResults)[1,Firm]) > printf("\n") > > printf("{txt}Average Firm Model{c |} Coef SampSE > t-stat p-val\n") > printf("{hline 18}{c +}{hline 52}\n") > for (mi=1; mi<= Firm-1; mi++) { > > printf("{txt} %13s {c |}", FirmModelVar[mi]) > > for (mj=1; mj <=4; mj++) { > > printf("{res} > %9.4f",st_matrix(sFirmModelResults)[mj,mi]) > > } > > printf("\n") > > } > > } > end > > > Nick > n.j.cox@durham.ac.uk > > Thomas Jacobs > > Well call me pig-headed but I just could not let go of this until I > figured out how to get it working. In the end it required either > converting mata values(matrices) to stata locals(matrices) so they > could be passed to the mata function. I post it here not just for > posterity but for anyone else trying to pass a stata matrix to a mata > function within an ado file. Hopefully it will save someone the many > hours I spent trying to get it to work. Both eofb and > sFirmModelResults are stata matrices. The latter was created from a > mata matrix FirmModelResults using > > st_replacematrix("sFirmModelResults",FirmModelResults) > > and the ado follows: > > program ProduceResults > > version 10.1 > local EventBeginDay "`1'" > local EventEndDay "`2'" > local scolFirm "`3'" > > mata: OutputFn("eofb","sFirmModelResults") > > end > > version 10.1 > mata: > void OutputFn(eofb,sFirmModelResults) > { > printf("Results for Event Period beginning with trading day > %4.0f and > ending at day %4.0f.\n", > strtoreal(st_local("EventBeginDay")), > strtoreal(st_local("EventEndDay"))) > > colFirm = strtoreal(st_local("scolFirm")) > > FirmModelVar = st_matrixcolstripe("e(b)")[.,2] > > printf("Average Firm Adjusted R Square %12.4f\n", > > st_matrix(sFirmModelResults)[1,strtoreal(st_local("scolFirm"))]) > printf("\n") > > printf("{txt}Average Firm Model{c |} Coef SampSE > t-stat p-val\n") > printf("{hline 18}{c +}{hline 52}\n") > for (mi=1; mi<= colFirm-1; mi++) { > > printf("{txt} %13s {c |}", FirmModelVar[mi]) > > for (mj=1; mj <=4; mj++) { > > printf("{res} > %9.4f",st_matrix(sFirmModelResults)[mj,mi]) > > } > > printf("\n") > > } > > } > end * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**RE: st: Re: controlling output in the results window***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: Re: controlling output in the results window***From:*Thomas Jacobs <thomasjacobs@gmail.com>

- Prev by Date:
**st: RE: [Fwd: re: simultaneous equations]** - Next by Date:
**Re: st: Seemingly unrelated regression (SUR) test joint significance with clustered standard errors** - Previous by thread:
**Re: st: Re: controlling output in the results window** - Next by thread:
**RE: st: AW: RE: Problem looping over spells for an individual** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |