Announcement

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

  • psmatch2 set seed

    Hi Statalisters -- I need some help with the psmatch2 command.

    I've set the seed like others have shown so that I can replicate my results:

    Code:
     set seed 4578
    gen rand=uniform()
    sort rand
    But every time I rerun the code to match the kids, I get different ATT estimates each time. Any suggestions?

  • #2
    You haven't shown us all of your code, including where you put the psmatch2 command(s). Do as the FAQ states, and show us everything, exactly as typed and exactly as received back. Moreover you should, as the FAQ states, tell us the provenance of user-written commands.

    My guess is that you only had one set seed statement, followed by repeated psmatch2 commands. If you want to reproduce the same psmatch2 results each time, you should set the seed again (to the same value) before each execution of the psmatch2 command that you are repeating.

    Comment


    • #3
      You should also make sure your data is sorted on a unique identifier right before you set the seed.
      Depending on what commands you have between when you open your data set and this step, your data may or may not be in the exact same order every time you get to this section. If the data is in a different order when you get there you'll still get a different result each time even if you're generating the same sequence of random numbers.

      Comment


      • #4
        Also, even with just the code in the original post, you have sorted the data on the value of a uniform random variate stored as a float. Depending on the size of your data set, there is a certain probability that there will be ties in the variable rand, and that will mean you do not have a unique sort order for the data. You can reduce that probability by storing rand as a double, and you can reduce it even more by using a pair of random variates, both stored as doubles.

        You can check to see if you have ties in -rand- by running -isid rand, sort- instead of -sort rand-. If there are ties, Stata will stop and complain.

        All of that said, as the previous commenters have all suggested, there may well be other sources of non-uniqueness arising elsewhere in your code that you haven't shown us.

        Comment

        Working...
        X