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: Substituting an expression into an -IF- conditional statement
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Substituting an expression into an -IF- conditional statement
Date
Fri, 6 Dec 2013 14:50:57 +0000
A loop would be three lines at least. Here's one way to do it
foreach case in "date <= 10" "date <= 20" "date > 20" {
var a b c if `case', lags(1/2)
}
Personally I would leave the code as you have it given this question alone.
If you wanted to do stuff again and again with those three cases,
however, then a new variable, something like
gen case = ceiling(date/10)
or
gen case = cond(date <= 10, 1, cond(date <= 20, 2, 3))
might make your life a little easier, as you could do things like
bysort case : var a b c
Nick
[email protected]
On 6 December 2013 14:41, Jason Park
> I'd like to split the data sample into (1) date <= 10, (2) date > 10 &
> date <= 20, and (3) date > 20, and for each case, I need to run a VAR
> command.
> Of course, it can be run by submitting the following three lines separately:
> var a b c if date <= 10, lags(1/2)
> var a b c if date > 10 & date <= 20, lags(1/2)
> var a b c if date > 20, lags(1/2)
>
> But instead, I'd like to loop through them. Can I?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/