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

Re: RE: st: RE: Random assignment


From   Richard Williams <[email protected]>
To   [email protected], "[email protected]" <[email protected]>
Subject   Re: RE: st: RE: Random assignment
Date   Thu, 01 Jan 2004 10:09:27 -0500

At 05:42 PM 1/1/2005 +0800, =?GB2312?B?yNm58w==?= wrote:
i am new to stata,so i can't understand some stat functions.
can anyone explains what the following function means--y=uniform()<=0.6.
thank you!
I was curious too, and your question inspired me to (hopefully) figure it out. I figured it created a 0-1 dichotomy, and here is how I think it works. From the online docs:

"uniform() returns uniformly distributed pseudo-random numbers on the interval [0,1). This function takes no arguments, but the parentheses must be included."

So, if you just said, gen y=uniform() you would get a variable with values ranging from 0 to 1, with a uniform distribution, i.e. the mean would be around .5 but values distant from the mean would be just as likely to occur as values close to the mean. (You can try this and see for yourself.)

Now, given that this var has a uniform distribution, about 60% of the values will be <=.6, while about 40% of the time the values will be greater than .6

So, when you give the command, gen y=uniform()<=0.6, about 60% of the time the statement will be true, returning a value of 1; about 40% of the time it will be false, returning a value of 0.

So, the result is that y is a 0-1 dichotomy with a mean of around .6 (i.e. about 60% of the cases are coded 1, the rest are 0). It won't be exactly .6 because of random variability; the bigger your sample size is, the more likely it is to be about .6.

In the original problem the author had 50 missing cases that he wanted to replace with 0s and 1s, proportionate to the numbers of 0s and 1s that were present in the nonmissing data. So if, say, 60% of the nonmissing cases were 1s, about 60% of the missing cases could be randomly assigned a value of 1 while the rest were assigned 0s with the above command.

This is a nice way to create a dichotomy, but it might be nicer still to have a command something like gen y = dichot(.6), which would mean create a 0-1 dichotomy where 60% of the cases are 1s. I suppose it would be easy enough to create such a command yourself if you had frequent need for it.

-------------------------------------------
Richard Williams, Associate Professor
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: [email protected]
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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index