Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to sample from a Multinomial distribution


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: How to sample from a Multinomial distribution
Date   Wed, 27 Feb 2008 19:06:49 +0000 (GMT)

--- [email protected] wrote:
> I have to generate data for a sample, which has three groups (G1, G2
> and G3). In this respect,  the probability distribution for the G1,
> G2 and G3 follows a multinomial distribution with parameter vector P
> = (pG1 ,pG2 ,pG3 ).
> 
> I have used -genbinomial- to generate the first two groups, and then
> the last one is calculate by subtraction. Since this is not an
> elegant way to do that, is the any routine that does in Stata the
> task above mentioned ?

You can generalize the method discussed in (Buis 2007) as in the
example below:

*---------------- begin example --------------------
sysuse auto, clear
mata:
n = 100
p1 = .3
p2 = .5
draw = J(st_nobs(),3,.) 
for(i=1; i<=rows(draw); i++) { 
         trials = uniform(1,n) 
         g1 = trials :< p1 
         g2 = trials :>= p1 :& trials :< p1 + p2
         draw[i,.] = rowsum(g1), 
                     rowsum(g2), 
                     n - rowsum(g1) - rowsum(g2) 
}
idx = st_addvar("long", ("G1", "G2", "G3"))
st_store(.,idx,draw) 
end
sum G*
*------------------ end example ----------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

M.L. Buis (2007), "Stata tip 48: Discrete uses for uniform()", The
Stata Journal, 7(3), pp. 434-435. 

A pre-publication draft can be found here:
http://home.fsw.vu.nl/m.buis/wp/discrete.html


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Inbox. http://uk.docs.yahoo.com/nowyoucan.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