Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: drawnorm equivalent for different distribution types?
From
Scott Merryman <[email protected]>
To
[email protected]
Subject
Re: st: drawnorm equivalent for different distribution types?
Date
Mon, 2 Sep 2013 13:25:59 -0500
Perhaps something this:
clear
mat c = (1 , .5 \ .5, 1)
local mu1 = 2
local mu2 = 4
corr2data x y , corr(c) n(1000) double
gen double ru1 = normal(x)
gen double ru2 = normal(y)
qui {
forv j = 1/2 {
gen double randpois`j' = 0
local i 0
tempvar ds
gen double d`j' = exp(-`mu`j'')
gen byte `ds' = (ru`j'>d`j')
count if `ds'
while r(N) > 0 {
replace randpois`j' = randpois`j' + 1 if `ds'
local i = `i' + 1
replace d`j' = d`j' + /*
*/ exp(-`mu`j'' + `i'*log(`mu`j'') - lngamma(`i'+1)) if `ds'
replace `ds' = (ru`j'>d`j')
count if `ds'
}
}
}
drop d1 d2
sum randpois*
corr randpois*
scatter randpois1 randpois2, jitter(3)
Most of the code is lifted from Roberto Gutierrez's -genpoisson-
(-findit gendist- to locate and download).
Scott
> On Sun, Sep 1, 2013 at 3:21 PM, Ariel Linden, DrPH
> <[email protected]> wrote:
>> Hi All,
>>
>> Is there an equivalent to -drawnorm- for different distribution types? So
>> for example, let's say I wanted two Poisson distributed variables with a
>> correlation of 0.50? Or a chi-sq distribution, etc...
>>
>> Thanks!
>>
>> Ariel
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/