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

st: generating random variables from logistic distribution


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: generating random variables from logistic distribution
Date   Thu, 4 Aug 2005 16:24:28 -0400

Not clear to me either how so-called generalized logistic distribution relates to the garden variety one defined here. In any case here is a routine in the style of Hilbe that does the job, and a test of whether it appears to meet the specs (which it does for sufficiently large N):

capt program drop rndlog

*!version 1.0 04aug2005 CFBaum
* following syntax of J. Hilbe rnd package
* logistic distribution random number generator
* per David Harrison msg to Statalist 04aug2005
* Example: rndlog 1000 0 .5 [set obs 1000; 0 = mean; .5 = b]

program define rndlog
version 3.1
* set type double
cap drop xlogistic
qui {
local cases `1'
set obs `cases'
mac shift
local mn `1'
mac shift
local b `1'
mac shift
tempvar ran1
noi di in gr "( Generating " _c
gen double `ran1' = `mn' - `b'*log(1/uniform() - 1)
gen double xlog = `ran1'
noi di in gr "." _c
noi di in gr " )"
noi di in bl "Variable " in ye "xlog " in bl "created."
lab var xlog "Logistic random variable"
* set type float
}
end

clear

scalar mu=5
scalar b=3
rndlog 100000 mu b
su xlog,detail
assert reldif(r(mean),mu) < 0.01
assert reldif(r(Var),1/3*_pi^2*b^2) < 0.01
assert reldif(r(skewness),0) < 0.1
assert reldif(r(kurtosis)-3.0,6/5) < 0.1


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html


*
* 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