Page 1 of 1

Count and %change of observations between resets

Posted: Thu Apr 04, 2019 12:23 pm
by cholke
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

Re: Count and %change of observations between resets

Posted: Thu Apr 04, 2019 3:31 pm
by EViews Matt
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).