Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Stata code to run R code from within Stata and return certain pieces of the results as Stata macros


From   "Salah Mahmud" <[email protected]>
To   [email protected]
Subject   Re: st: Stata code to run R code from within Stata and return certain pieces of the results as Stata macros
Date   Sat, 31 May 2008 04:10:40 -0500

Thanks Sergiy,
You captured all the important requirements for the R-Stata bridging
routine. I guess implementing the whole thing as a plugin is possible
too but perhaps a bit of an overkill. And so is using XML as the
exchange medium.

salah


On Fri, May 30, 2008 at 1:07 PM, Sergiy Radyakin <[email protected]> wrote:
> Dear Salah,
>
> all what you describe seems feasible, but the implementation depends
> on your specific tasks.
>
> From what I know, R is very communicative, so it can import/export
> data in multiple formats. With the -foreign- package it should read
> Stata datasets (not sure about V10?, but Stata 8/9 should be no
> problem).
>
> -rsource- does nothing more than launching R with a parameter and
> capturing results, so no magic here: technically it does not run
> r-code IN Stata, it runs r-code OUTSIDE of Stata, and Mr Newson
> described that very specifically both in the title and description of
> -rsource-. However, some still interpret that as "r-program will be
> executed in Stata".
>
> The trick would be to develop a easy and robust protocol of
> communication between Stata and R. The easiest would be to write all
> the parameters in a text file, and agree on the location of the
> response (this can itself be a parameter). This should be no problem
> if the function returns just a number, such as p-value, but if you
> want more complex response (such as output, variables, etc) this must
> be organized neatly.
>
> I had something similar with Visual Basic, before switching to
> plugins. Stata created a number of text files containing lists of
> strings to process and passed the names of the lists and the name of
> the response file to the Basic program. Then it patiently waited for
> the file to be created (technically it waited for the flag-file,
> before reading the response file, because when the response file
> appears, it is not necessarily complete/closed).
>
> Best regards,
>   Sergiy Radyakin
>
>
>
>
> On 5/30/08, Salah Mahmud <[email protected]> wrote:
>> Dear all,
>>
>> Just wondering if you know of tried and tested Stata code (do or ado)
>> that would run a piece of R code from within Stata and return certain
>> pieces of the results as a Stata macro.
>>
>> For instance, I would like to call an R function that would perform
>> certain calculations on certain variables (that also has to be
>> exported to R) and then return certain pre-specified info (from the R
>> object) such as a P-value as a Stata macro. Perhaps a  combination of
>> rsource, outsheet, some R object parsing and intext  that hides all
>> the mechanistic details of running R from within Stata.
>>
>> Thanks,
>>
>> salah mahmud
>>  Canada
>> *
>> *   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/
>
*
*   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/



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