Statalist


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

AW: st: AW: Randomly assigning values with a specific distribution


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: AW: Randomly assigning values with a specific distribution
Date   Mon, 5 Oct 2009 15:01:06 +0200

<> 

My -irecode- approach creates a variable with values that range from 1 to 5.
If ever you wanted irregularly spaced values (your x1 to x5), you could
enter them into


*************
clear*
set obs 100000

tempvar unif
gen `unif'=runiform()

gen byte x= /* 
your x1 equals 3 here
*/ inrange(`unif',0,.4)*3+ /* 
your x2 equals 7
*/ inrange(`unif',.4,.5)*7+ /* 
your x3 equals 12
*/ inrange(`unif',.5,.8)*12+ /* 
your x4 equals 19
*/ inrange(`unif',.8,.85)*19+ /* 
your x4 equals 34
*/ inrange(`unif',.85,1)*34

ta x
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Dorothy Bridges
Gesendet: Montag, 5. Oktober 2009 14:56
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: Randomly assigning values with a specific distribution

Thank you Martin!

On Mon, Oct 5, 2009 at 8:51 AM, Martin Weiss <martin.weiss1@gmx.de> wrote:
>
> <>
>
>
>
> *************
> clear*
> set obs 10000
>
> gen x=irecode(runiform(), 0, 0.4, /*
> */  0.5, 0.8, .85)
>
> ta x
> *************
>
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Dorothy
Bridges
> Gesendet: Montag, 5. Oktober 2009 14:50
> An: statalist@hsphsun2.harvard.edu
> Betreff: st: Randomly assigning values with a specific distribution
>
> Dear Statalist:
>
> I would like to create a random variable taking five different values
> whose distribution mirrors that of another variable.  In other words,
> I have one variable whose distribution is, say:
>
> value      %
> x1         40
> x2         10
> x3         30
> x4         5
> x5         15
>
> ... and I want to create another variable with the same values and
> distribution, but randomly assigned.  Something like gen randomvar =
> mydist() instead of uniform().
>
> Thanks,
> Dorothy
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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