Smpl of most recent consecutive positive values

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

Smpl of most recent consecutive positive values

Postby tvonbrasch » Mon Aug 12, 2019 10:29 am

Hi
How can I get the smpl of the most recent period with consecutive positive values for a series?
Thomas

EViews Matt
EViews Developer
Posts: 562
Joined: Thu Apr 25, 2013 7:48 pm

Re: Smpl of most recent consecutive positive values

Postby EViews Matt » Mon Aug 12, 2019 1:28 pm

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.

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

Re: Smpl of most recent consecutive positive values

Postby tvonbrasch » Tue Aug 13, 2019 6:17 am

Excellent, thanks!


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 14 guests