Page 1 of 1

Smpl of most recent consecutive positive values

Posted: Mon Aug 12, 2019 10:29 am
by tvonbrasch
Hi
How can I get the smpl of the most recent period with consecutive positive values for a series?
Thomas

Re: Smpl of most recent consecutive positive values

Posted: Mon Aug 12, 2019 1:28 pm
by EViews Matt
Hello,

How about this, where "x" is the series of interest:

Code: Select all

genr(r) tmp = @nan(tmp(1) + ((x(1) > 0) <> (x > 0)), x > 0)
series tmp2 = @recode(tmp = 1, 1, na)
string first = tmp2.@first
string last = tmp2.@last
smpl {first} {last}

The temporary auxiliary series "tmp" creates a numbering for every region of consecutive (non)positive values in such a way that the last positive region is always associated with the number one, and "tmp2" is a pseudo-dummy series (na/1 instead of 0/1) useful for retrieving the endpoints of said region.

Re: Smpl of most recent consecutive positive values

Posted: Tue Aug 13, 2019 6:17 am
by tvonbrasch
Excellent, thanks!