[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 |
Sun, 1 Mar 2009 17:51:02 -0000 |

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/

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

- Prev by Date:
**Re: AW: st: AW: RE: Problem looping over spells for an individual** - Next by Date:
**RE: st: AW: RE: Problem looping over spells for an individual** - Previous by thread:
**Re: AW: st: AW: RE: Problem looping over spells for an individual** - Next by thread:
**Re: st: Re: controlling output in the results window** - Index(es):

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