Announcement

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

  • importsav: new package for converting SPSS file to Stata (requires R) on GitHub

    I know this sounds quite weird after Stata 16 was released, but anyway I made a package called importsav which converts SPSS file to Stata with the help of R packages haven, foreign and bit64.

    Code:
    net from https://raw.githubusercontent.com/jh-min/importsav/master
    to install the package.

    Code:
    github install jh-min/importsav
    will also work if you installed user-written package github.

    The key difference between importsav and other user-written packages such as importspss or usespss is that the support of non-English labels in both variables and values. Although Stata has officially supported this feature since version 16, importsav would still be an alternative for users with older versions of Stata.

    In order to use importsav, you need to install R on your system first. But after that, there is no need of running R at all. The essential idea underlying importsav is not to interrupt your workflow within Stata. With this command, you don’t need to escape Stata for data conversion. importsav will automatically write and execute R code for you.

    Acknowledgement:
    This program owes a lot to importspss by Gabriel Rossman, whereis by Germán Rodríguez and rcall by E. F. Haghish. I am grateful for their informative programs.

    Disclaimer:
    I tested importsav 3.0 with Stata 14 and 15 on Windows and earlier version of importsav with Stata 15 on macOS. Please let me know if it goes wrong.

  • #2
    Originally posted by JeongHoon Min View Post
    I know this sounds quite weird after Stata 16 was released, but anyway I made a package called importsav which converts SPSS file to Stata with the help of R packages haven, foreign and bit64.

    Code:
    net from https://raw.githubusercontent.com/jh-min/importsav/master
    to install the package.

    Code:
    github install jh-min/importsav
    will also work if you installed user-written package github.

    The key difference between importsav and other user-written packages such as importspss or usespss is that the support of non-English labels in both variables and values. Although Stata has officially supported this feature since version 16, importsav would still be an alternative for users with older versions of Stata.

    In order to use importsav, you need to install R on your system first. But after that, there is no need of running R at all. The essential idea underlying importsav is not to interrupt your workflow within Stata. With this command, you don’t need to escape Stata for data conversion. importsav will automatically write and execute R code for you.

    Acknowledgement:
    This program owes a lot to importspss by Gabriel Rossman, whereis by Germán Rodríguez and rcall by E. F. Haghish. I am grateful for their informative programs.

    Disclaimer:
    I tested importsav 3.0 with Stata 14 and 15 on Windows and earlier version of importsav with Stata 15 on macOS. Please let me know if it goes wrong.
    Thanks for the nice program. It needs some clarification, however, as there are some persisting errors:

    Code:
    . importsav "D:\wm.sav"
    location of R has not been stored with whereis.ado
    importsav.ado searches expected directories...
    importsav.ado could not find R in expected directories
    ...will depend on the PATH environment variable
    invalid syntax
    r(198);

    Comment


    • #3
      Sonnen Blume Thank you for reporting it, I fixed the error and added requirements section on help document to articulate environment variables. (I've briefly tested it by removing R from my PC and installing R on the location other than the default.) It is now available on github and I'll ask Kit Baum to update program on SSC. Thank you

      Comment


      • #4
        Thank JeongHoon Min for your quick feedback!

        So I'm getting it correctly, R has to be installed in the same folder as Stata, and should be running in parallel right? If so, then it can be a bit stiff compared with Sergey Radyakin's -usespss- command, whose's only issue is incompatibility with 64bit OSs. Once that gets fixed, importsav may become less attractive.

        Comment


        • #5
          Sonnen Blume No, R can be installed in any folder, and by the default location what I meant was C:\Program Files\... or C:\Program Files (x86)\..., which is the path set by default during the installation of R. If R has not been installed on the default location, you can inform -importsav- of the path to R by using either -whereis- or environment variables(The error you reported was related to the latter way).

          And you don’t need to run R by yourself, -importsav- will run (and quit) R automatically(I’m not sure what you meant by “should be running in parallel” though).

          Also, I agree that -usespss- will be enough for most users, given that the beta version of -usespss- supports 64bit. But my main purpose was to keep variable/value labels from original SPSS dataset, not only those written in English but also in other non-Latin characters such as Korean(-usespss- even cannot convert datasets with Korean labels...). Thank you for interested in -importsav-

          Comment


          • #6
            Thanks to Kit Baum, hotfix is now available on SSC.

            Comment


            • #7
              Hi Jeong Hoon Min,

              I tried importsav, but received the following error message:

              Code:
              location of R has not been stored with whereis.ado
              importsav.ado searches expected directories...
              haven has failed to convert your data
              importsav.ado is trying to use foreign...
              foreign has failed to convert your data
              your data could not be converted using R packages
              do you have any idea why such error occur? I really appreciate it if you could share some insights.

              Best,

              Elghafiky

              Comment


              • #8
                Elghafiky Bimardhika Hi, first of all, sorry for late response. There was a major update of R after latest version of -importsav- and that made -importsav- incompatible with new version of -haven- of R. I fixed the wrong behavior and hotfix is now available on github. I emailed Kit Baum to update program on SSC and will post again when it is available on SSC.

                But if hotfix does not solve your problem, then the source of the problem might be R packages itself, not -importsav-. It seems that both -haven- and -foreign- sometimes fail to convert certain SPSS file. I will try to figure out a way to get around but I'm not sure how long it will take. It would be helpful if you don't mind sending me the example data file which -importsav- does not work on.

                Thank you for reporting the issue and I'm really sorry for my laziness.

                Comment


                • #9
                  Thanks to Kit Baum, version 3.0.5 of -importsav- is now available on SSC.

                  Apart from this, there was a minor update of -importsav- in order to support automatic conversion of periods in variable name into underscores. This is needed because SPSS allows periods in variable names and -haven- fails to convert SPSS datasets with variable names containing periods.

                  To figure out where errors come from, I'm planning to add an option to print R logs in -importsav- and I won't update -importsav- on SSC utill then. Minor updates will only be available via github. Again, I would be most grateful if anyone could send me SPSS dataset which -importsav- does not work on.

                  Comment


                  • #10
                    Hi JeongHoon Min

                    I am getting the same error message as Elghafiky when I try to convert my .sav file: "your data could not be converted using R packages".

                    I am using the latest version of R (4.4.1) and I have checked that both the haven and foreign packages are installed in R. Do you have any suggestion on how I might be able to fix this issue?

                    Thanks,
                    Sarah Hill

                    Comment

                    Working...
                    X