Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[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 <[email protected]>
To   [email protected]
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 <[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index