Count and %change of observations between resets

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

cholke
Posts: 2
Joined: Mon Sep 11, 2017 8:10 am

Count and %change of observations between resets

Postby cholke » Thu Apr 04, 2019 12:23 pm

I have two timeseries. One is a numerical value. The other is a 0/1 series that operates as a flag. I would like to count the number of observations and percent change in the numerical series between when the flag changes value.


Thanks,
Craig

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

Re: Count and %change of observations between resets

Postby EViews Matt » Thu Apr 04, 2019 3:31 pm

Let "x" be the numerical series and "flag" be the 0/1 series, how about this:

Code: Select all

series obs = @recode(flag(-2) = na, @obsid - 1, @recode(flag(-1) <> flag(-2), 1, obs(-1) + 1))
series pc = 100 * (x - x(-obs)) / x(-obs)
smpl if flag <> flag(-1)

I'm assuming a full-sample evaluation. The "obs" series holds the number of observations since the previous flag change and the "pc" series holds the percentage change in the numerical series. The smpl statement excludes all the observations for which the flag didn't change (and presumably "obs" and "pc" are of no interest).


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 3 guests