Eric Powers <epowers@moore.sc.edu> 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
ddrukker@stata.com
*
* 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/