15

Is it possible to call Stata functions from R?

3 Answers 3

13

Not directly, i.e. there is no package I am aware of that implements a bridge.

You can always call external programs using system() but that is neither elegant nor efficient. That said, you could prepare data in R, write it out, call Stata and then read the results in; see help(system).

3
12

There's now an RStata package on CRAN that bridges R and Stata.

1
3

The real problem is that Stata doesn't have an interactive interpreter you can pass arguments to.

Dirk is right; you can just go ahead and write the data to a common format (if size is large and speed is an issue, fixed width is safe), but you can also just use .dta throughout the process, using read.dta in R and natively reading in Stata.

Also, in R you can call to the system() you can pass a do file or a string containing a bunch of Stata commands.

So, generally, trying to use Stata for this or that task may or may not be worth it, especially if an R equivalent is close by.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.