Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: -generate- and run time contingencies

From   "Steichen, Thomas J." <>
To   <>
Subject   st: RE: -generate- and run time contingencies
Date   Mon, 30 Jan 2006 11:07:24 -0500

Mike Lacy writes in part:
> One feature of Stata with which I continue to experience difficulty 
> concerns how to assign a value to a variable based on a run time 
> contingency. As a simple illustration, consider the goal of assigning 
> a uniform r.v. value to a variable, while rejecting values less than, 
> say, 0.8.  If  -while- was sensitive to run time values of variables, 
> I would do:
> gen x = uniform()
> while (x < 0.8) {
>    replace x = uniform()
> }
> Obviously, this construct that would work in many languages does not 
> work as desired in Stata, and just as obviously, there are other ways 
> to accomplish the same end in Stata [  gen x = 0.8 + 0.2*uniform() ].

The general approach is to recognize that Stata is inherently vectorized.


  . gen x = uniform()
  . replace x = uniform() if x < 0.8

accomplishes what you want.

The above says replace x only if the currrent (run time) value of x is less than 0.8.


CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s),
contains information that may be confidential, protected by the
attorney-client or other legal privileges, and/or proprietary non-
public 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/or any of its attachments (if any) by unintended recipients
is not authorized and may be unlawful.

*   For searches and help try:

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