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

Re: st: generating random number with restriction to add to a variable in current dataset


From   Richard Williams <[email protected]>
To   [email protected]
Subject   Re: st: generating random number with restriction to add to a variable in current dataset
Date   Wed, 23 Feb 2005 17:31:11 -0500

At 05:45 PM 2/23/2005 -0300, you wrote:
Dear all,

I want to generate random numbers to add to the linear
index of a probit model (xb) so that I can predict
precisely the 1/0 observed outcomes.
Therefore, for y=1 I want to draw a random number
(vi)from a N~(0,1) so that xb+v>0 and for y=0 I want
to draw a random number (vi) so that xb+v<=0. Any idea
on how I can draw these numbers and add them to the
index in few steps?

Best wishes

Fabio
I'm not clear how random numbers could do this. In order for xb+v>0| y=1, the lower bound of v has to be -xb. I suppose you could set v to the max of -xb and some random number, but then you are not really adding random numbers anymore. Or perhaps you shift your random variable so its lower bound is -xb (if y = 1) or its upper bound is -xb (if y = 0). Something like this after a probit would do that (this may need a little tweaking):

predict xb, xb
drawnorm resid0 resid1
egen residmin1 = min(resid1) if y==1
gen newresid = resid1 - residmin1 - xb + .001 if y==1
egen residmax0 = max(resid0) if y==0
replace newresid = resid0 - residmax0 - xb - .001 if y==0
gen newxb = xb + newresid
bysort y: sum xb newxb


The newresid won't be normal (0,1) though, the mean will be shifted so as to meet the necessary upper/lower bound conditions.

There may be better solutions, but whatever you do I don't think you can just say the numbers are drawn from a N(0,1) because there have to be constraints on the residuals to achieve what you want.


-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
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