[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: RE: How to sample from a Multinomial distribution |

Date |
Wed, 27 Feb 2008 22:15:19 -0000 |

The last line of code should be gen y = cond(uniform() < 0.5, 1, cond(uniform() < 0.8, 2, 3)) but as said it's not a solution to the problem stated. Nick Cox 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/

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

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

- Prev by Date:
**st: RE: storing tables and values in tables** - Next by Date:
**st: evaluating probabilities using kdensity** - Previous by thread:
**st: RE: How to sample from a Multinomial distribution** - Next by thread:
**st: marginal effects on Tobit** - Index(es):

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