Help in finding the corresponding date of an observation

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

sudesh
Posts: 51
Joined: Fri Nov 03, 2017 7:30 pm

Help in finding the corresponding date of an observation

Postby sudesh » Thu Mar 08, 2018 3:57 pm

Hi,

I have a series with the following observations: NA, 0 , 1 and values > 1.

The 1 represent the entry date and the value > 1 represent the exit date

In the series, I have severals entry and exit dates.

I would like to extract all entry and exit dates and save them into a table.

I need to save them into a table, because I will use the entry and exit date to calculate the return of each period

I don't know how to retrieve the corresponding dates and how to store them into a table.

Any help will be greatly appreciated.

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

Re: Help in finding the corresponding date of an observation

Postby EViews Matt » Thu Mar 08, 2018 4:54 pm

Hello,

Are the periods defined by each entry/exit date pair non-overlapping? In other words, are there never two entry dates without an exit date between them, and vice versa?

sudesh
Posts: 51
Joined: Fri Nov 03, 2017 7:30 pm

Re: Help in finding the corresponding date of an observation

Postby sudesh » Fri Mar 09, 2018 6:39 am

Hi,

Each entry date is followed by an exit date , non overlapping period

For exemple, the first date is always an entry date( 01 jan 1970), the next is an exit date ( 01 mars 1970) and then the second entry date might be ( 01 june 1980) and so on.

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

Re: Help in finding the corresponding date of an observation

Postby EViews Matt » Fri Mar 09, 2018 9:58 am

This should get you started.

Code: Select all

series tmp = @obsid
' Create a two-column matrix where the first column holds entry observation numbers and the second column holds exit observation numbers. Assumes the series of interest is called "x".
matrix m = @transpose(@unvec(@convert(tmp, "if x >= 1"), 2))
' Convert the matrix into a table, changing observations to dates along the way.
table t
for !r = 1 to @rows(m)
   t(!r, 1) = @otod(m(!r, 1))
   t(!r, 2) = @otod(m(!r, 2))
next
delete tmp m

sudesh
Posts: 51
Joined: Fri Nov 03, 2017 7:30 pm

Re: Help in finding the corresponding date of an observation

Postby sudesh » Mon Mar 12, 2018 7:26 am

Thanks alots, it's working


Return to “Programming”

Who is online

Users browsing this forum: Google [Bot] and 22 guests