Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

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>
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 13:20:08 +0200

Many thanks.
Kind regards,
Gwinyai

On 3/25/13, Maarten Buis <maartenlbuis@gmail.com> wrote:
> 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/
>
*
*   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/


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