Announcement

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

  • Loading data from R dataframe to Stata using rcall

    Hello,

    I am trying to run a simple analysis (to be more accurate, to create a dataframe) in R using the R package EpisodeR available on GitHub. As I want to work on the data in Stata, I am trying to use the community-contributed package rcalll, which is also available on GitHub.

    After installing both packages, I tried running the following code, knowing that st.load(df) is the rcall function to load data from R to Stata

    Code:
    rcall: library(EpisodeR); ///
    df <- get_episode(data = EpisodeR::vdem, ///
                      start_incl = 0.01, ///
                      cum_incl = 0.1, ///
                      year_turn = 0.03, ///
                      variable = "v2xca_academ"); ///
    st.load(df)
    Sadly, I get this message:
    "R failed to export Stata data set"

    I know that my EpisodeR code is correct because when I run it in RStudio, it creates the dataframe. So there is something I'm doing wrong when I try to bring it back into Stata.
    I am using Stata 18, R 4.5, and all packages are updated.

    I am clearly doing something wrong. If someone can help me to identify it, that would be much appreciated!

    Thank you,
    Nir

  • #2
    Hi Nir, I can repeat your problem. Hope haghish can see this post.

    Comment


    • #3
      Hi Nir, based on the error, it seems that R fails to create the Stata dataset. You could try to see if readstata13 R package can create the dataset (this package is used by rcall). You could also use the "debug" option to investigate the script files.

      Comment


      • #4
        Dear haghish, thanks for reply. library readstata13 runs sucessfully in R. And rcall: library(EpisodeR)... failed in Stata. Below is the information.

        Code:
        library("readstata13")
        data (cars)
        
        # Save the 'cars' dataset to a Stata file
        save.dta13(cars, file = "cars.dta")
        
        # Read the saved Stata file back into R
        dat <- read.dta13("cars.dta")
        Code:
        . do "C:\Users\chen_\AppData\Local\Temp\STD68e0_000000.tmp"
        
        . rcall: library(EpisodeR); ///
        > df <- get_episode(data = EpisodeR::vdem, ///
        >                   start_incl = 0.01, ///
        >                   cum_incl = 0.1, ///
        >                   year_turn = 0.03, ///
        >                   variable = "v2xca_academ"); ///
        > st.load(df);
        Error in library(EpisodeR) : �����ڽ�'EpisodeR'������ֵij̼��� R failed to export Stata data set
        
        . 
        end of do-file
        P.S. I want to confirm your personal website. Is http://www.haghish.com/ still under your control? I can't find any information about you in this website.
        ​​​​​​​
        Click image for larger version

Name:	_20250521225036.png
Views:	1
Size:	1.55 MB
ID:	1777797

        Comment


        • #5
          That's not what I meant. I meant to try readstata13 to export the dataset that you create with the EpisodeR. Basically, you are giving rcall an object that may not be a straight forward dataframe (I don't know, I'm just guessing). If I were you, I would first test the R code, and use readstata13 (or any other package) to create the Stata dataset within R. It simplifies debugging your code, but based on what I see, it doesn't seem to be rcall's error.

          The website is no longer mine, and is full of AI-generated meaningless text! :-)

          Comment


          • #6
            haghish

            ​​​​​​​
            The website is no longer mine, and is full of AI-generated meaningless text! :-)
            Noted, but that seems to imply that you shouldn't mention it in your signature.

            Comment

            Working...
            X