Announcement

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

  • Rademacher random variable


    Hello all,

    I am interested in generating independent realizations of a Rademacher random variable. Is this something that can be implemented in Stata?

    Thank you

  • #2
    The following three approaches should all yield pseudorandom numbers with a uniform distribution on the integers -1 and +1.
    Code:
    generate r1 = case(runiformint(0,1)==0,-1,+1)
    generate r2 = 2*runiformint(0,1)-1
    generate r3 = case(runiform(0,1)<=0.5,-1,+1)

    Comment


    • #3
      Dear William,

      Thank you very much for the suggestions. Approach 2 worked, but not the other 2 - I got the following error,

      nknown function case()

      findint case did not return anything.

      Any advice is appreciated.

      Thank you

      Comment


      • #4
        Sorry, I meant cond() not case().

        Comment


        • #5
          Thank you for the clarification - all approaches work without any problem.

          Thank you for the help

          Comment

          Working...
          X