[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: [SPAM] - st: Returning Mata Results to Stata - Email has different SMTP TO: and MIME TO: fields in the email addresses |

Date |
Tue, 16 Oct 2007 12:47:36 -0500 |

Dear Alexis, Thanks very much for providing a solution. I must confess I am still such a mata newbie (still under 24 hours) that I do not follow your algorithm in spite of repeated attempts. I finally went with a workaround that entailed writing the matrix of results out as a text file with the following commands: //Write Results matrix to file fh = fopen("Results.txt", "w") for (j=1; j<=rows(Results); j++) { fput(fh,sprintf("%22.0g\t%22.0g\t%22.0g\t%22.0g\t%22.0g\t%22.0g", Results[j,1],Results[j,2],Results[j,3], Results[j,4], Results[j,5],Results[j,6])) } fclose(fh) I then exit mata, clear stata and insheet the resulting file back into stata. I still need to modify so that I keep all the stata variables I need in the final mata Results matrix due to the need to clear stata before re-reading. I realize this is not an elegant solution but at least it seems to be working so far. Thanks again for taking the time to write - I will continue to study your solution in hope that I can finally develop some understanding of passing variables and data back and forth between Stata and Mata. Sincerely, TOm On 10/16/07, ??? ???? <icef-research@hse.ru> wrote: > Thomas, > > Judging on my experience with Mata, I guess your problem is due either to matrix size when you export your results from Mata back to Stata, or by the format of the data you export (Mata is not terribly efficient in coding data as numeric or string, as far as I can see). > > If you process your data in Stata cycle, your problem almost surely can be solved by exporting your results to Stata one-by-one. The algorithm is this: > > 1. Create an empty variable Result_1 in Stata > > 2. Start cycle in Stata (indexed by `s'), in which run your Mata routine for each observation, and write its result in 1-by-1 matrix "tempmata". Export the result within the same iteration `s' of Stata as 1-by-1 matrix using > - st_matrix("tempmata", tempstata) - > > 3. Code > - local tstat tempstata[1,1] - > - replace Result_1`s'=`tstat' - > > 4. Repeat the process for the next value of s up to the end of the cycle, i.e. until you fill the variable Result1, and so on for the other variables. > > I am not sure this is the most efficient solution, but with Stata 9.2 and corresponding Mata it should work. > > Alexis Belianin > ICEF, Moscow > > >-----Original Message----- > >From: owner-statalist@hsphsun2.harvard.edu > >[mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Thomas Jacobs > >Sent: Tuesday, October 16, 2007 6:33 PM > >To: StataList > >Subject: [SPAM] - st: Returning Mata Results to Stata - Email > >has different SMTP TO: and MIME TO: fields in the email addresses > > > > > >I am trying to decipher the manuals for mata to do something that I > >imagine is pretty simple, returning my results from mata to (ideally) > >matching observations for my starting data in Stata. I basically use > >the st_data command to move my stata based observations into a mata > >matrix as follows: > > > >I = st_data(., "var 1", "var2", etc.) > > > >I now have a mata based matrix, I, that has all of my data including > >identification data such as company number and trading day. > > > >I next use the information variables to produce some new values and > >let us assume I create a new matrix in mata called results that has > >the following form > > > >Results = (Company Number, Trade Day, Result 1, Result 2, etc.) > > > >where the rows are different observations. > > > >Back in Stata I have variables such as > > > >Company Number, Trade Day, Input Data1, Input Data 2, etc. > > > >My goal is to append the mata based information into new stata > >variables with matching observations that would appear as follows: > > > >Company Number, Trade Day, Input Data 1, ...Input Data n, Result 1, > >...Result n, etc. > > > >I have struggled in vain to decipher the mata manual for commands such > >as creating new stata variables from mata (st_addvar), adding > >observations (st_addobs), and modifying or moving values (st_store) > >but have had zero luck in getting anything to work. At this point I > >am thinking I may simply need to write an output file from mata, close > >mata and insheet the output file into stata to append to the dataset > >there. > > > >Can anyone provide any thoughts or suggestions on how to proceed? > > > >With great thanks, > > > >Tom > > > >-- > >Thomas Jacobs > >* > >* For searches and help try: > >* http://www.stata.com/support/faqs/res/findit.html > >* http://www.stata.com/support/statalist/faq > >* http://www.ats.ucla.edu/stat/stata/ > > > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > -- Thomas Jacobs * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Returning Mata Results to Stata***From:*"Thomas Jacobs" <thomasjacobs@gmail.com>

**RE: [SPAM] - st: Returning Mata Results to Stata - Email has different SMTP TO: and MIME TO: fields in the email addresses***From:*"??? ????" <icef-research@hse.ru>

- Prev by Date:
**st: FORTRAN 77's GO TO <label> CONTINUE into Mata** - Next by Date:
**st: RE: Negative Binomial Regression** - Previous by thread:
**RE: [SPAM] - st: Returning Mata Results to Stata - Email has different SMTP TO: and MIME TO: fields in the email addresses** - Next by thread:
**Re: st: Returning Mata Results to Stata** - Index(es):

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