Statalist


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

st: Re: Generate a random variable with a range constraint


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Generate a random variable with a range constraint
Date   Sat, 6 Dec 2008 18:47:31 +0100

Well, you are asking for a normal, equivalent to

g wt2=rnormal(70, 10.5)


which could theoretically range from minus to plus infinity. Why do you want it restricted? You can of course


drop if wt<45 | wt >95

and you would not lose too many observations, as 45 and 95 are far out in the tails of N(70, 10.5)...

HTH
Martin
_______________________
----- Original Message ----- From: "David Collins" <dcoll@ms.umanitoba.ca>
To: <statalist@hsphsun2.harvard.edu>
Sent: Saturday, December 06, 2008 6:35 PM
Subject: st: Generate a random variable with a range constraint


I apologise for what may be a fairly rudimentary question. I want to generate a random variable (wt), n = 5000; as follows;

 set obs 5000
 set seed 1000
 g wt = 70 * rnormal(1, 0.15)

However, wt also needs to be constrained as follows, 45 < wt < 95. I am having difficulty incorporating the constraint into the generate function, and would appreciate any help.

--David

--
David M Collins, Ph.D.
Dean & Professor, Faculty of Pharmacy
University of Manitoba, Apotex Centre
750 McDermot Avenue, Winnipeg  MB  R3E 0T5
CANADA.

Tel. 204-474-8794  Fax: 204-474-7617
Email: dcoll@ms.umanitoba.ca

CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s)
is intended for the addressee(s) only and may contain confidential
information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and
any of its attachments (if any) is not authorized and may be unlawful.

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