Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: "If" in a local variable


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: "If" in a local variable
Date   Tue, 30 Nov 2010 09:03:45 +0000 (GMT)

--- On Nov 29, 2010, at 8:39 PM, Laurie Molina wrote:
> > I want to set the value of a local variable,
> > conditional of the value of some other variable, but
> > i think the option "if" is not availabe for a local
> > variable.
> > What i would like to do is the following:
> > local a= 1 if `b' > `c'
> > local a= 2 if `b' < = `c'

--- On Tue, 30/11/10, Eric Booth wrote:
> You can use the  -if- command instead of the "if"
> qualifier.  See -help ifcmd-.   You probably want
> this:
>     
>      if `b' > `c'  local a= 1
<snip>

An alternative to Eric's solution is to use the 
-cond()- function:

local a = cond(`b' > `c', 1, 2)

Hope this helps,
Maarten

PS Just a clarification on terminology:

Variables in Stata-speak are columns in a data-matrix.
So `a' is not a "local variable", as it is not a column
in a data-matrix. Instead it is a "local macro", often
abreviated as a "local". Options are things that are 
placed after the comma in a command, so -if- is not 
an option. It is called a qualifier if it appears
at the end of a command (but before the comma) and a 
command when it appears at the front. 

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index