Announcement

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

  • Converting a code from Stata to R

    Hello guys,
    I'm new to both Satata and R. I'm trying to do a regression to find the causal effect between the use of pesticides and birds' population, and i'm now using a Arellano-Bond estimator, i have this code for Satata and i want to convert it to R. I tried different versions but i don't even get the same sign of effect of the lagged dependant variable, in Satata its positive, while my versions in R give me a negative sign which doesn't make much of a sense since an increase in bird's population of the past period should have a positive impact on the bird population in the current period. Can you guys tell me how the correct code in R should be written?
    Here's the Stata code

    xtabond2 sum_grass_no L.sum_grass_no crop_acre total_neon develop_acre mtemp1 mtemp4 mtemp5 mtemp6 lag_mtemp12 pcpn1 pcpn4 pcpn5 pcpn6 lag_pcpn12 pop_den, gmm(L.( sum_grass_no ),lag(1 2)) iv(lag_fertp pest_price develop_acre mtemp1 mtemp4 mtemp5 mtemp6 lag_mtemp12 pcpn1 pcpn4 pcpn5 pcpn6 lag_pcpn12 pop_den, eq(diff) ) robust twostep


    Also, i'm using the plm package on R and the the command is pgmm.
    Thanks for the help!

  • #2
    I would be happy for you if you got an answer here, but I guess it's unlikely.

    In my experience you're more likely to get an answer in a R forum.

    And it's better to say what you want to do in English and statistics than to ask for a translation from Stata to R. There are usually many more people who know how to do something in one language than who know about how to do it in two.

    Comment


    • #3
      I'll be honest with you, and this is coming from a long term user of Stata (I'm 24, and I've had Stata since I was 19ish) but for what it's worth: I don't know about your reasons for using both software here, but just from experience, I'd advise you being familiar with both software first before attempting any of the more, shall we say, refined commands. That is, you need to learn the languages that R and Stata are written in. Learn the basic syntaxes, learn the idiosyncrasies. Learn how to clean and do simple analyses in each first. Read whatever R's equivalent of the help files are, so on and so forth. Even within Stata, there are subtle differences between things like lassoregress, lasso linear, and cvlasso that you'll only know once you've read the syntaxes/help files for those files. Synth in Stata has subtle differences between Synth in R; and so on. I suspect that's what's going on here.

      Sometimes, "translating" the languages is straightforward; I know because I've done it for simpler concepts. Other times, not so much. As a comfortable Stata user, it would make me quite nervous to do the work I do in R, because of my lack of familiarity with its language and other details I care quite a lot about. It's intimidating for me. I'm sorry I can't be of more help, but the best advice I could give, assuming (maybe incorrectly) you haven't read the help files for both, is to do just that. My mentor once said that the help files might as well be written in Russian sometimes, but at the end of the day, for issues like this at least, it seems like a thorough reading of them is the ideal course of action here.

      One day, I want to be bilingual in Stata and R. Just not today, I guess.

      Comment


      • #4
        My mentor once said that the help files might as well be written in Russian sometimes, but at the end of the day, for issues like this at least, it seems like a thorough reading of them is the ideal course of action here.
        The R help files for the packages I use have been less intuitive than the Stata help files. I think the main difference is in the worked examples. It takes a lot of work to write a clear example. R package authors are one or two person shops. In contrast, I assume that with Stata, there are technical writers helping the programmers to flesh out the examples.

        To the original example, just translating a Stata estimation command into the R syntax for a specific package should be doable ... if you understand the underlying statistical model and the Stata command, which I do not, so I am unfortunately not able to help.
        Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

        When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

        Comment

        Working...
        X