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

st: Re: local .... if


From   "Steichen" <[email protected]>
To   <[email protected]>
Subject   st: Re: local .... if
Date   Sat, 27 Mar 2004 09:16:23 -0500

Lars Korsholm wrote:

> Can anyone help me with the following
> what I would like to do is something like
> local val= x if id==124
>
> I know one dirty way:
> preserve
>  keep if id==124
>  local val=x
> restore

Lars, I do not understand exactly what you wish to accomplish. Perhaps you
mean:

    if id == 124 local val=x

This will set val = x only if id == 124 and, if x is a variable, the value
of val will be x[1] (the value of the first observation of x).  val will not
exist if there is no id with value 124 and val did not exist prior to the
above command.

If, as I suspect, you want val to have value x[124], you will need to
explicitly set it:

    if id == 124 local val=x[124]

The -if id == 124- part may not be needed depending on the logic of your
program... if so, just set

   local val=x[124]

Tom


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