[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" <>
To   <>
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)...

----- Original Message ----- From: "David Collins" <>
To: <>
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 M Collins, Ph.D.
Dean & Professor, Faculty of Pharmacy
University of Manitoba, Apotex Centre
750 McDermot Avenue, Winnipeg  MB  R3E 0T5

Tel. 204-474-8794  Fax: 204-474-7617

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:

*   For searches and help try:

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