## 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: 423
Joined: Fri Apr 15, 2011 5:35 am

### Smpl of most recent consecutive positive values

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: 410
Joined: Thu Apr 25, 2013 7:48 pm

### Re: Smpl of most recent consecutive positive values

Hello,

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.@firststring last = tmp2.@lastsmpl {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: 423
Joined: Fri Apr 15, 2011 5:35 am

### Re: Smpl of most recent consecutive positive values

Excellent, thanks!