Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Maarten Buis <maartenlbuis@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Is there a better way of allocating individuals into different categories based on the probability of an event? |

Date |
Mon, 25 Mar 2013 09:40:19 +0100 |

On Sat, Mar 23, 2013 at 4:16 AM, Gwinyai Masukume wrote: > Is there a better way of executing the code below which assigns > individuals into the Non-smoker and Smoker categories based on the > probability of smoking in pregnancy? <snip> Assuming 84% of > women do not smoke during pregnancy I would rewrite the lines > gen smoker1=int(1+(50000-1)*runiform()) > gen smoker=0 if smoker1 < 42000 > replace smoker=1 if smoker1 >= 42000 like this: gen byte smoker = runiform() < .16 For more see: M.L. Buis (2007), "Stata tip 48: Discrete uses for uniform()", The Stata Journal, 7(3), pp. 434-435. <http://www.stata-journal.com/article.html?article=pr0032> -- Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * 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/

**Follow-Ups**:**Re: st: Is there a better way of allocating individuals into different categories based on the probability of an event?***From:*Gwinyai Masukume <parturitions@gmail.com>

**References**:**st: Is there a better way of allocating individuals into different categories based on the probability of an event?***From:*Gwinyai Masukume <parturitions@gmail.com>

- Prev by Date:
**st: time in xtmixed** - Next by Date:
**Re: st: time in xtmixed** - Previous by thread:
**Re: st: R: Is there a better way of allocating individuals into different categories based on the probability of an event?** - Next by thread:
**Re: st: Is there a better way of allocating individuals into different categories based on the probability of an event?** - Index(es):