Announcement

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

  • gen random variable with F distribution

    Dear Stata users,

    I cannot figure out which function to use to generate random variable that has F distribution with any degrees of freedom, e.g. F(2,10). I found formulas for chi2 distribution, normal and uniform distribution, however, I cannot find for F distribution.

    e.g.
    gen chi10=rchi2(10)
    gen x = rnormal(0, 1)

    What is the formula for generating random variable that has F distribution?

    Thank you very much.

    Best regards,
    Aleksandra

  • #2
    Maybe something like one of these two?
    Code:
    set seed 1897213257
    quietly set obs 1000
    
    generate double f210a = rchi2(2) / 2 / (rchi2(10) / 10)
    
    generate double randu = runiform()
    generate double f210b = invF(2, 10, randu)

    Comment


    • #3
      Code:
       
       generate double f210b = invF(2, 10, runiform())
      should work too. As Joseph Coveney implies, setting the seed is a good idea.

      Comment


      • #4
        Joseph Coveney & Nick Cox thank you both for your answers. The values differ in variables f210a and f210b, shouldn't they be the same if we set seed the random number generator?

        Thank you.

        Best regards,
        Aleksandra

        Comment


        • #5
          You should, I think, expect similarity of distribution, not identical values. That's the nature of randomness. In addition, F(2, 10) is moderately skewed, so modestly prone to outliers.

          Comment

          Working...
          X