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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: How to sample from a Multinomial distribution |

Date |
Wed, 27 Feb 2008 21:50:54 -0000 |

I don't see that you need any program to do this. Suppose the probabilities are 0.5 0.3 0.2. gen random = uniform() gen y = cond(random < 0.5, 1, cond(random < 0.8, 2, 3)) What -cond()- is doing may be clearer laid out like this: cond(random < 0.5, 1, cond(random < 0.8, 2, 3)) If the random number is less than 0.5, assign 1; Else if it is less than 0.8, assign 2; Else assign 3. A pitfall that I have fallen into myself is to tempted to rewrite this as gen y = cond(uniform() < 0.5, cond(uniform() < 0.8, 2, 3)) That is not equivalent, as each call of -uniform()- is distinct. Nick n.j.cox@durham.ac.uk tiago.pereira@incor.usp.br 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 ? I have not found anything yet. * * 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/

**Follow-Ups**:**st: RE: RE: How to sample from a Multinomial distribution***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: How to sample from a Multinomial distribution***From:*tiago.pereira@incor.usp.br

- Prev by Date:
**RE: st: Critical values for stock and yogo test when the cluster option is used** - Next by Date:
**st: RE: CI for a difference in proportions** - Previous by thread:
**Re: st: How to sample from a Multinomial distribution** - Next by thread:
**st: RE: RE: How to sample from a Multinomial distribution** - Index(es):

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