Announcement

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

  • Converting R code into Stata code

    Hi,

    I'm looking for a way (preferably hiring a skilled RA to do this for $) to convert data analyses that were done in R into Stata code that reproduces those results.
    Can someone recommend anything?

    Thanks!

  • #2
    Maybe you should give an example, showing list members what type of code you are referring to? Advanced programming or statistical analyses?

    (My subjective view is that ordinary analyses are easier to code in Stata, but developing functions/programs is easier in R.)

    Comment


    • #3
      This is of course possible, but the optimal way of proceeding really depends on what you're trying to do, e.g.:
      1. Transfer code that is frequently used and/or critical to your operations
      2. Learn how to do things you currently do in R in Stata by having someone translate some of your code
      3. Want to continue/finish your project in Stata, and want existing R code translated for consistency
      4. ...
      For this type of work, the tech adage "you can have it done good, fast, or cheap—pick two" is especially apt. And this depends entirely on the nature of the code you're looking to translate: how well was it written, does it use advanced features of the R language or rely on 3rd party packages (e.g., tidyverse), etc. Most folks are better at one language than the other, and you'll have to decide whether you should favor someone who is more proficient in Stata (important for Items (1) and (2) above) or someone who is more proficient in R (might be faster if your R code uses advanced features or is not particularly well-written, but won't necessarily result in good quality Stata code). In addition, you need to determine how much of the code is data manipulation (which requires programming skills only to translate) versus how much is statistical estimation/modeling (for this, replicating the results in Stata may require significant statistical knowledge about how the models are implemented in each package). Finally, unless the job is very small or especially easy, you may find that this is not cheap and should decide whether you really need the code translated (you don't if you just want to distribute the code so that the results can be replicated).
      Last edited by Phil Schumm; 04 Sep 2021, 13:45.

      Comment


      • #4
        Originally posted by Christopher Bratt View Post
        Maybe you should give an example, showing list members what type of code you are referring to? Advanced programming or statistical analyses?

        (My subjective view is that ordinary analyses are easier to code in Stata, but developing functions/programs is easier in R.)

        It is for a published, peer reviewed paper in social science for which I have the original R code. I'm trying to find a way to convert the relevant analyses to Stata and then continue working there with the data.
        There aren't too many analyses and the R code isn't overly long and most of the econometric analyses are straightforward (no advanced programming). I appreciate Phil's suggestions but I'm still trying to outsource this task.

        Comment


        • #5
          Thanks for answering. You might post a link to the paper?

          That said, learning a second language for coding can be useful. See link.

          https://statisticalhorizons.com/r-sh...econd-language

          Comment


          • #6
            For now I'm only looking for someone who has the R <-> Stata skillset and hire that person.

            I'm not disputing that learning a second language is useful but when I have a problem with a car then I go to a mechanic and don't try to watch YouTube videos on how to fix it myself. Same applies here.

            Comment


            • #7
              Nowadays cars are built so that you need a mechanic any way for anything non-trivial!

              All analogies break down somewhere.

              Just as a detail, people sometimes ask on Stack Overflow for translations between Stata and R. Those questions have very low success rates, mostly for the reasons identified by Phil Schumm. The naive idea is that it's like asking for a translation between say French and Italian, but it really isn't. Or rarely is. Translating more than about ten lines of code can be really hard work. If the code is something at research level -- and yours is -- it is necessary often to read documentation on both sides, study examples, and so forth, to work out what is happening. A translation may need a lot of original coding.

              Many people know something of both languages but real fluency in both is rare. I have used R occasionally. I have looked through lots of books on or using R, and sometimes thought, How do you do that in Stata? But it's almost never a matter of trying to translate directly, line by line. It's a matter of seeing what is being done -- in terms of data management, graphics or statistics -- and then figuring out Stata code. This kind of experience may or may not be relevant to your precise needs.

              The most common single request I've seen is for the R equivalent of egen In Stata egen is a very useful rag-bag of stuff, but in my understanding R people really had and have no call whatsoever to reinvent it in similar form.

              Money may be the right incentive but I'd say your best bet is to seek an academic co-author who knows your topic and who knows Stata, but I appreciate that may not be easy and that it may be too far from what you want. (Not volunteering.)

              Comment


              • #8
                I've found people to translate (or try to) on upwork.com.

                Comment


                • #9
                  The most common single request I've seen is for the R equivalent of egen In Stata egen is a very useful rag-bag of stuff, but in my understanding R people really had and have no call whatsoever to reinvent it in similar form.
                  I have been among those who requested something similar to -egen-, as I went to R after working with Stata for a year or two. Or, I wanted to find something similar to Stata's concept of 'macro' (I still think the term is strange). But then a guy called Nick Cox wrote something interesting (at Stack Overflow): One should use each language at their own premises.

                  Then I learned that R is a functional language, you can develop nearly everything into a tiny (or complex) function, an object (or mini-program). And indeed, you can do what -egen- does (e.g. egen mean by group) with a simple function you write as part of an R script. R is a programming language, Stata is foremost statistical software. So, yes, translating from one to the other is a bit more complex than translating from French to English. BTW, I don't miss -egen- when in R, but I do miss local macros and the simplicity of Stata's data management, so I jump back and forth between the two.

                  As far as analogies go, I wouldn't phone a car mechanic and ask Can you fix my car? They would probably want to know a bit more before promising to fix it. So, I believe showing what type of help you want could increase the chances of getting assistance. For instance, I still have a hard time reading simple R code written in its original language, before the tidyverse arrived in R. And conversely, some of those who are trained in traditional R find tidyverse difficult to grasp.

                  To conclude: I would show what you want to have translated. And I believe Nick's suggestion to have a co-author is the best recommendation yet.

                  Comment


                  • #10
                    While I'd agree that a translation might be difficult, I don't think it's unreasonable to see if there is someone interested in and capable of doing the work. My understanding of local norms here is that using StataList to solicit someone to do work is acceptable. On that count, I'd suggest you just repost your request with a more direct subject, e.g. "Seeking to hire someone to translate analyses in R into Stata," describing the scope of work a bit, and then letting interested parties contact you directly. At some universities where I've worked, there is a stable of graduate student assistants who work for social science statistical computing support services, and they are commonly cross-trained in various statistical packages and also have friends with particular skills in one package or another. I'd think that someone like that would be happy to pick up some "side work," and perhaps your request here might get noticed by or passed on to such a person.
                    Last edited by Mike Lacy; 05 Sep 2021, 15:06.

                    Comment

                    Working...
                    X