@elem bug

For notifying us of what you believe are bugs or errors in EViews.
Please ensure your copy of EViews is up-to-date before posting.

Moderators: EViews Gareth, EViews Moderator

nupogodi
Posts: 53
Joined: Thu Jun 03, 2010 12:50 am

@elem bug

Postby nupogodi » Thu Oct 16, 2014 2:56 am

@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")

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

Re: @elem bug

Postby EViews Gareth » Thu Oct 16, 2014 8:14 am

You can only enter the observation number if your workfile is undated. If your workfile is dated you need to enter the date.
Follow us on Twitter @IHSEViews

ErikG
Posts: 78
Joined: Wed Jan 23, 2013 1:18 am

Re: @elem bug

Postby ErikG » Tue Dec 15, 2015 7:27 am

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)

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

Re: @elem bug

Postby EViews Gareth » Tue Dec 15, 2015 10:05 am

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))
Follow us on Twitter @IHSEViews


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 5 guests