Save Maximum of a Series

For questions regarding programming in the EViews programming language.

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

stefanp
Posts: 63
Joined: Wed Sep 30, 2015 12:24 am

Save Maximum of a Series

Postby stefanp » Thu Apr 14, 2016 8:24 am

Hey,

I have a panel data set which contains N cross-sections and T periods.

I would like to save the maximum value of a each cross section of a certain series and save the maximum value including the identifier as well as the date.

I thought of something like this:

Code: Select all

genr max=@max(series01, "@first @last if ident=""a""")
However, this will assign the maximum value to all entries (i.e. for all N and T the same value).

I think it would help to use the @max command in the sampling environment, but I dont know how to apply it in this case.

Best

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Save Maximum of a Series

Postby EViews Gareth » Thu Apr 14, 2016 10:29 am


stefanp
Posts: 63
Joined: Wed Sep 30, 2015 12:24 am

Re: Save Maximum of a Series

Postby stefanp » Fri Apr 15, 2016 5:27 am

Honestly, it doesnt really help.

I would be happy to further explain my issue if it has not been clear so far.I kindly ask you to tell me what remains to be clarified in that case

Best

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Save Maximum of a Series

Postby EViews Gareth » Fri Apr 15, 2016 7:03 am

Just use @maxsby with the cross-section id series as your by-variable

stefanp
Posts: 63
Joined: Wed Sep 30, 2015 12:24 am

Re: Save Maximum of a Series

Postby stefanp » Wed Apr 20, 2016 8:25 am

Suppose I have a series called "maxvalue". This series contains different values for each date for each cross-section. The cross sections are identified by the series "ident". I need to access the maximum value for each cross section of the series "maxvalue". The maximum value of "maxvalue" might be at different points in time for each cross section.

If if use something like

Code: Select all

show@maxsby(maxvalue, ident)
the same value (indeed the maximum value) for a cross sections is assigned to all points in time. I require it to be the maximum value at the point in time when it is maximized and zero or NA otherwise.

Still havent figured out how to get there.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Save Maximum of a Series

Postby EViews Gareth » Wed Apr 20, 2016 8:33 am

Code: Select all

series mymaxes = @recode(maxvalue = @maxsby(maxvalue,ident), @maxsby(maxvalue, ident), na)

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Save Maximum of a Series

Postby EViews Glenn » Wed Apr 20, 2016 9:40 am

Gareth, If I'm interpreting correctly, I think the original question was a bit more complicated, as the poster wanted the historical max at a each point in time. (If that interpretation is correct, the answer is only a tiny bit more complicated than your answer -- if I'm wrong, you all can just ignore me).

Suppose we have a dated panel structured workfile with the series F of interest.

We are going to write a recursion to identify the historical maximum for the cross-section at a given point in time. First, we seed the recursion.

Code: Select all

smpl @first @first series cummax = f
Next, for the remaining periods we compute the historical maximum by comparing the current value to the lagged historical maximum.

Code: Select all

smpl @first+1 @last cummax = @recode(f>cummax(-1), f, cummax(-1))
Note that in since this is a dated panel workfile, the by-cross-section part of the calculation is handled naturally via the sample and recursion.

Lastly, we do the recoding to NAs.

Code: Select all

smpl @all series mymaxes = @recode(cummax=f, cummax, na)
Last edited by EViews Glenn on Wed Apr 20, 2016 9:51 am, edited 1 time in total.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Save Maximum of a Series

Postby EViews Glenn » Wed Apr 20, 2016 9:50 am

And of course, I forgot that we have a @cummax function which simplifies things even further as the whole first part of my post can be done in a single line.

Code: Select all

series cummax = @cummax(f) series mymaxes = @recode(cummax=f, cummax, na)

stefanp
Posts: 63
Joined: Wed Sep 30, 2015 12:24 am

Re: Save Maximum of a Series

Postby stefanp » Mon Apr 25, 2016 4:10 am

Thank you, Gareth's suggestions does the trick.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests