Page 1 of 1

Save Maximum of a Series

Posted: Thu Apr 14, 2016 8:24 am
by stefanp
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

Re: Save Maximum of a Series

Posted: Thu Apr 14, 2016 10:29 am
by EViews Gareth

Re: Save Maximum of a Series

Posted: Fri Apr 15, 2016 5:27 am
by stefanp
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

Re: Save Maximum of a Series

Posted: Fri Apr 15, 2016 7:03 am
by EViews Gareth
Just use @maxsby with the cross-section id series as your by-variable

Re: Save Maximum of a Series

Posted: Wed Apr 20, 2016 8:25 am
by stefanp
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.

Re: Save Maximum of a Series

Posted: Wed Apr 20, 2016 8:33 am
by EViews Gareth

Code: Select all

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

Re: Save Maximum of a Series

Posted: Wed Apr 20, 2016 9:40 am
by EViews Glenn
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)

Re: Save Maximum of a Series

Posted: Wed Apr 20, 2016 9:50 am
by EViews Glenn
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)

Re: Save Maximum of a Series

Posted: Mon Apr 25, 2016 4:10 am
by stefanp
Thank you, Gareth's suggestions does the trick.