Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: - uniform() - random variable not uniformly distributed overinterval


From   Richard Williams <Richard.A.Williams.5@nd.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: - uniform() - random variable not uniformly distributed overinterval
Date   Wed, 09 Mar 2005 20:53:24 -0500

At 05:19 PM 3/9/2005 -0800, Deborah Garvey wrote:

Dear listers:

I am generating a random number with the goal of (randomly) assigning
children who report multiple races to a single race category for
purposes of analysis.  I'd like to evenly distribute children across
single race categories.  However, when I use uniform() to generate a
random number, I don't get an even split:
...
I am puzzled.  I would expect median = mean = 0.5 for a uniform number
defined over [0,1). This must be a simple, basic question, but neither
changing the - set seed -, changing the interval to [0,1], or changing
the observations selected seems to solve this problem.  A search of
on-line help, the list archives and the Stata FAQs didn't give me much
insight either.
Actually, it is very unlikely that a random variable will produce exactly a 50/50 split. If you repeated this process several times, you would find that sometimes the first group was bigger, sometimes the 2nd group was bigger. By chance alone, sometimes the mean and median will be greater than .5, sometimes they will be less.

There are various solutions. If you don't have it already, I would suggest installing -egenmore- (give the command -findit egenmore- to find and install.) Then, give the command

egen r = rndsub() if k_race == 801, ng(2)

If I've done this right, I believe you'll get 1155 in your first group and 1154 in your 2nd. You should probably precede this with a -set seed- command so you can replicate your results, e.g.

set seed 12345
egen r = rndsub() if k_race == 801, ng(2)
replace k_race2 = 100 if r = 1
replace k_race2 = 200 if r = 2



-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: Richard.A.Williams.5@ND.Edu
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc

*
* 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/




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