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

From |
Thomas Jacobs <thomasjacobs@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Fri, 20 Feb 2009 22:30:24 -0600 |

Kit, I am back again, having studied your slides. I have some conceptual questions. I was unable to convert my called do file to an ado nor understand several of the posts people submitted in response to my inquiries on the conversion. So, having read your slides I took the section of my called do file that I was unable to silence with the quietly command and attempted to make it a mata function, but I have been unable to get that to work, either. One thing I have noticed is that the Stata manuals in M-1 ado - using Mata with ado files and your slides always seem to imply that a mata function is called from a stata program passing stata variables. In my case, I have a stata program with significant sections of mata code and mata variables created prior to the called mata function, so I am left wondering how does one pass mata variables to a mata function? If this is not permitted, does this mean I need to broaden my mata function to include all the mata code in the stata program and pass stata variables as in the examples? Here is the code section I am trying to convert to a mata function right below the end of the quietly command where colFirm, FirmModelResults, and FirmModelVar are mata variables created earlier: *end quietly } mata: //Used one pass loop to clean up output for (mh=1; mh<=1;mh++) { 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"))) printf("Average Firm Adjusted R Square %12.4f\n",FirmModelResults[1,colFirm]) 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",FirmModelResults[mj,mi]) } printf("\n") } } end Here is the do file I use to create the function (as a side question, every time I run this the replace option fails giving me an error that the .mo already exists and I have to manually delete it and restart stata. I have posted this to tech support to see if this is a bug but thought I would mention in case you see something I am doing wrong): *PooledResultsMo.do version 10.1 mata: void PooledResultsMo(real scalar colFirm, string scalar FirmModelResults, string scalar FirmModelVar) { 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"))) printf("Average Firm Adjusted R Square %12.4f\n",FirmModelResults[1,colFirm]) 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",FirmModelResults[mj,mi]) } printf("\n") } } mata mosave PooledResultsMo(), dir(PERSONAL) replace end And here is the error I get when I try to execute the entire program where a do file calls a do file which calls PooledResultsMo: . *end quietly . } . mata:PooledResultsMo("`colFirm'", "`FirmModel'", "`FirmModelVar'" ) PooledResultsMo(): 3253 <tmp>[1,1] found where real required <istmt>: - function returned error r(3253); end of do-file r(3253); end of do-file r(3253); Any thoughts GREATLY appreciated! Tom On Fri, Feb 20, 2009 at 4:54 PM, Thomas Jacobs <thomasjacobs@gmail.com> wrote: > > Kit, > > Thanks for sharing this. I missed it having worked off Nick's earlier > reply regarding a sample ado. It is very helpful. > > Tom > > On Tue, Feb 17, 2009 at 2:13 PM, Christopher Baum <baum@bc.edu> wrote: > > <> > > Tom said > > > > Thanks for the reply. Please forgive my ignorance but I am unsure how to > > follow your advice. My Stata programming experience only recently extended > > to successfully calling a do file from another do with arguments, etc. Is > > creating a function simply creating an ado file? If not, is there anywhere > > in the manuals that I might find an example? > > > > As a matter of fact, > > > > http://ideas.repec.org/p/boc/fsug08/7.html > > > > Kit Baum, Boston College Economics and DIW Berlin > > http://ideas.repec.org/e/pba1.html > > An Introduction to Modern Econometrics Using Stata: > > http://www.stata-press.com/books/imeus.html > > > > * > > * 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/ > > > > > > -- > Thomas Jacobs -- Thomas Jacobs * * 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**:**st: re: controlling output in the results window***From:*Christopher Baum <baum@bc.edu>

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

- Prev by Date:
**Re: st: RE: ivreg2/xtivreg2, clustering, and the covariance matrix of moment conditions** - Next by Date:
**st: RE: Estimation of differences of logistic regression models in three groups** - Previous by thread:
**Re: st: re: controlling output in the results window** - Next by thread:
**st: Re: controlling output in the results window** - Index(es):

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