Utility Functions
Sample Index Functions
A key EViews feature is the ability to work with subsamples of observations. There are two common ways of defining a subsample of observations in a workfile. One method is to specify a set of (0, 1) (boolean) identifiers that indicate whether each observation in the workfile is included in the subsample. A second method is to specify a list of index values for the observations in the subsample.
In some cases, working with the boolean indicators is more convenient. In others, especially when the subsample is sparse and direct access to the observation is useful, working with the index values may be preferred.
EViews 14 provides new workfile page functions that allow you to extract information from the workfile and workfile sample, and to convert between the two methods.
Current Sample Index (@pagesmplidx)
The @pagesmplidx function returns a vector object containing the index values for the observations in the current sample.
Suppose we have an annual workfile from 2001 to 2024, and have set the workfile sample to a subset of observations. The commands
wfcreate(wf=awf) a 2001 2024
smpl 2002 2003 2010 2011
create a workfile containing annual observations from 2001 to 2024, then sets the sample to contain observations from 2002–2003 and 2010–2011. There are 24 observations in this workfile which may be identified by index values 1 to 24. Then
vector ids = @pagesmplidx
will return IDS containing {2, 3, 10, 11}.
Observations Index (@pageidx)
The @pageidx(arg) function returns a vector object containing the index values for the observations in the workfile specified in arg.
The argument may be a vector of date numbers, an svector of date strings, or a string object or string literal containing a space delimited list of dates.
Observation specifications that are outside of the workfile range will be ignored.
For example,
wfcreate(wf=qwf) q 2001 2024
vector id1 = @pageidx("2010q2 2010q3 2021q1 2023q4")
creates a workfile containing quarterly data from 2001 to 2024 and an ID1 vector containing the values {38, 39, 81, 92}.
Boolean Indicators (@pageinidx)
The @pageinidx(arg) function, where arg is a vector containing observation index values, returns a vector object, sized to match the workfile page length, that includes (0, 1) indicators for each observation, with 1’s assigned to index elements in arg, and 0’s elsewhere.
If the arg contains index values that are outside of the workfile range, the function will return an error.
If we have the commands
vector id2 = @fill(10, 27, 30, 40)
vector incl = @pageinidx(id2)
then INC1 is a vector with 0’s everywhere except for the elements 10, 27, 30, and 40. Note that these commands are a concise equivalent to the commands
vector inc2 = @zeros(@wfrange)
inc2(10) = 1
inc2(17) = 1
inc2(30) = 1
inc2(40) = 1
Using @pageidx to identify observation indices and then feeding the result to @pageinidx offers a quick way of specifying a subsample of observations using dates:
wfcreate(wf=qwf) q 2001 2024
vector inc3 = @pageinidx(@pageidx("2010q2 2010q3 2021q1 2023q4")
stom(inc3, include_series)
smpl @all if include_series = 1
Matrix Utility Functions
EViews 14 offers a few new matrix utility functions that make common operations easier to perform.
The
@lower and
@upper functions make it easy to create lower and upper triangular matrices from matrix and sym objects. The functions allow you to specify an offset from the main diagonal so you can create strict lower and upper matrices, or matrices which zero out all but small lower or upper triangular regions of the source matrix:
EViews 14 also adds the
@implodeu function to create a symmetric matrix from the upper triangle of a square matrix. This function complements the existing
@implode which creates the sym from the lower triangle of a matrix.
The new
@incr function allows for adjusting all of the columns or rows of a matrix by incrementing with a vector. You may, for example, use this function to quickly add or subtract a multiple of a vector from each column of a matrix, or add or subtract a multiple of a rowvector from each row of a matrix, eliminating the need for expensive Kronecker product operations.
String and Date Vector Functions
Earlier versions of EViews offered an extensive library of string and date functions which allowed for manipulation of string values and date numbers. You could, for example, easily compare string values, insert strings into other strings, or extract a specific word from a string containing a list of words. Or you could manipulate date numbers to find a date two weeks in the future, or determine the number of days between two dates.
Unfortunately, the EViews library for these functions was generally limited to functions of scalar values. If, for example, you wanted to perform a set of on a set of string dates held in an svector, you needed to extract each element of the svector individually, perform operation on the string and any corresponding date number, and then place the result into a new vector or svector.
EViews 14 features a completely revamped string and date function library which features vector support. Functions which previously only took single string or date number values now operate seamlessly with arguments in vector form.
Consider, for example the
@left function which returns the
left-most characters in a string
. The first argument of the function corresponds to an alphanumeric
, and the second argument is a numeric
.
For this function, EViews 14 will return different types of results for different combinations of valid
and
argument types. The command
= @left("When in the course", 4)
returns the string “When” which is displayed in the EViews status line.
If A is a vector object containing the values 1, 2, 3, 4,
svector s1 = @left("When in the course", A)
will produce an svector S1 containing the strings “W”, “Wh”, “Whe”, and “When”. In this case, EViews evaluates the function repeatedly using the literal value “When in the course” for
paired with each of the four values of A for
.
Alternately, if V is a 4-element svector,
svector s2 = @left(V, 4)
will return a 4-element svector S2 containing the left-most 4 characters of the corresponding elements of V.
Lastly,
svector s3 = @left(V, A)
will pair the elements of the svector V and vector A as defined above, returning an svector containing the first character of the first element of V, the first two characters of the second element of V, the first three characters of the third element of V, and the first four characters of the fourth element of V.
To take another example, suppose we wish to specify a string date, find the corresponding underlying date number, manipulate that number to add various numbers of weeks, and then find a string representation of the new date number.
We may now perform a vectorized version of this operation which finds a string representation for 11 weekly days beginning at an initial scalar date:
wfcreate d7 2000 202
vector weeks = @seq(0, 1, 11)
string startdate = "May 1, 2000"
svector enddates = @datestr(@dateadd(@dateval(startdate), weeks, "W"))
This operation uses the
@dateval function to convert the initial string into a date number, the
@dateadd function to find the date numbers associated with the initial date number and the following 10 weeks, and the
@datestr function to convert the result back into a string.