Page 1 of 1

counting periods after marked dates

Posted: Wed Aug 04, 2010 11:46 am
by dasilver
I am new to Eviews programming (with Eviews 6) and I have the following question:

I have time series data with events on certain dates marked by 0's and 1's. I would like to count the number of time periods between each event. For example, I would like the first period after an event to be 1, the second period 2, etc., until the next event when the count will reset at 0. Is there a way to do this? I have tried using loops and if/then logic but have been unsuccessful.

Thank you.

Re: counting periods after marked dates

Posted: Wed Aug 04, 2010 11:55 am
by EViews Gareth
Assuming you have a series called "EVENT" that has a 1 every time there is an event, and 0 otherwise, the counter could be generated with:

Code: Select all

series counter = @recode(event=1,counter(-1)+1,0)
It might mess up if the very first observation of the workfile has a an event.

Re: counting periods after marked dates

Posted: Wed Aug 04, 2010 12:36 pm
by dasilver
thank you very much for the reply - it was very helpful.

For future reference though, the condition was switched. If 1 is the event, then we want to increment when event = 0 as shown below.

series counter = @recode(event=0,counter(-1)+1,0)