Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Generating a logistically distributed random variable.


From   "David M. Drukker, Stata Corp" <[email protected]>
To   [email protected]
Subject   RE: st: Generating a logistically distributed random variable.
Date   Mon, 19 Aug 2002 10:37:27 -0500

Eric Powers <[email protected]> asked:

> To generate a normal (0,1) random variable you use
> invnorm(uniform()).  How do you generate a random variable that is
> logistically distributed?

Using the logistic distribution function we have
              exp(x)
	p = -----------
	    1 + exp(x)

Solving for p as a function of x yields

           -      -
           |    p |
        ln |------| = x 
	   | 1 - p| 
	   -      -


So, here is a log of one way to implement this method in Stata
	   

. set obs 1000
obs was 0, now 1000

. gen double p = uniform()

. gen lg = ln(p/(1-p))

. sum lg

    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
          lg |    1000   -.0038691   1.805678  -7.249973   6.240144


. di sqrt(_pi^2/3)
1.8137994


I hope that this helps.

--David
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index