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
Count and %change of observations between resets
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
EViews Matt
- EViews Developer
- Posts: 583
- Joined: Thu Apr 25, 2013 7:48 pm
Re: Count and %change of observations between resets
Let "x" be the numerical series and "flag" be the 0/1 series, how about this:
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).
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)
Who is online
Users browsing this forum: No registered users and 2 guests
