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
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: "If" in a local variable
Date
Tue, 30 Nov 2010 03:28:53 +0000
<>
You can use the -if- command instead of the "if" qualifier. See -help ifcmd-. You probably want this:
if `b' > `c' local a= 1
or
if `b' > `c' {
local a= 1
}
Here's an example using auto.dta :
***************!
sysuse auto, clear
ds make, not
foreach v in `r(varlist)' {
qui su `v', d
if `r(mean)' > 30 local a one
if `r(mean)' <= 30 local a two
di in y "`v'--> `a'"
}
***************!
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249
http://ppri.tamu.edu
On Nov 29, 2010, at 8:39 PM, Laurie Molina wrote:
> Hello all,
>
> 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'
>
> Any idea of how can i get those conditional values for the local variable `a'?
>
> Thank you all in advance!
>
> LM
> *
> * 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/