Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exporting Stata results to R

    I would like to use Stata and get results from analyses into R (as a data frame in R, for manipulation there). Stata can return various results for postestimations and manipulations (-return list-), but what would be the easiest way to get a matrix from Stata into R?

    This is an old question, as shown by this thread on StackOverflow: https://stackoverflow.com/questions/...on-result-to-r, but I believe so far with no good answer.

    Does anyone have any recent experience with such a procedure, and maybe a recommendation? I assume one option might be to use -putexcel-, and then read those excel data into R. But maybe there's a better solution out there.

    (-Rcall- would not solve my problem. I need to run code from R or at the very least import results from Stata into R as a dataframe. I run all analyses and documentation from within R/RStudio, using the knitr package. Stata is currently used for initial data management only, but I'd like to add the option to let Stata do some analyses.)

  • #2
    What I do is just save the results in a dataset (if they're in a matrix, you can use svmat to convert them to a dataset), and then use R to read in the data using the haven package. That will import the results as a dataframe (well actually, a tibble).

    Comment


    • #3
      (and if you want to run everything from R, including your initial data management do-file, you can look into the rstata package, which lets you run Stata do-files from within R (and even within code chunks in a markdown document).

      Comment


      • #4
        Thanks, Isaac. I will try your suggestion.
        (I use the RStata package for running do-files.)
        Last edited by Christopher Bratt; 20 Sep 2019, 09:21.

        Comment

        Working...
        X