Page 1 of 1

@elem bug

Posted: Thu Oct 16, 2014 2:56 am
by nupogodi
@elem gives an error message but should return the value of series at observation 85 (Eviews 8.1 Command Ref page 530)

workfile m 1995 2009
smpl 2001 2002

series a = nrnd
scalar value = @elem(a, "85")

Re: @elem bug

Posted: Thu Oct 16, 2014 8:14 am
by EViews Gareth
You can only enter the observation number if your workfile is undated. If your workfile is dated you need to enter the date.

Re: @elem bug

Posted: Tue Dec 15, 2015 7:27 am
by ErikG
A subroutine to obtain individual observations with structured data that is not dated is shown here in code with an example of how to use it

Code: Select all

WfCreate C:\temp\test.wf1 u 3 alpha code Code(1) = "A" Code(2) = "B" Code(3) = "C" series z = @obsnum PageStruct() Code Call getElem(z,"C",%Value) Subroutine GetElem(series x, string %index, string %ReturnValue) %IdSeries = @PageIds if @wcount(%IdSeries) <> 1 Then @uiprompt("Page must be structured with a single identifier, program aborted") stop endif !iC = 0 for !i = 1 to @ObsRange if {%IdSeries}(!i) = %index Then %ReturnValue = @str(x(!i)) !iC = !iC + 1 endif next if !iC = 0 Then @uiprompt("Warning the index " + %index + " does not exist") endif if !iC > 1 Then @uiprompt("Warning: more than one occurerence of the index " + %index + " found, the last value is used") endif endsub @uiprompt(%Value)

Re: @elem bug

Posted: Tue Dec 15, 2015 10:05 am
by EViews Gareth
Nifty.

Slightly more efficient than using your for loop would be to set the sample and take the max of the series:

Code: Select all

smpl if {%idseries} = %index %ReturnValue = @str(@max(x))