User’s Guide : EViews Fundamentals : Working with Data : Series
Basic Assignment
Using Samples
Dynamic Assignment
Implicit Assignment
Using the Command Window
One of the primary uses of expressions is to generate new series from existing data or to modify the values in an existing series. Used in combination with samples, expressions allow you to perform sophisticated transformations of your data, saving the results in new or existing series objects.
The current discussion focuses on the basic numeric series object. Users who wish to work with alphanumeric or advanced series features should see “Working with Data (Advanced)” and “Series Links”.
To create or modify a series, select Quick/Generate Series… or click on the Genr button on the workfile toolbar. EViews opens a window prompting you for additional information.
You should enter the assignment statement in the upper edit box, and the relevant sample period in the lower edit box.
The assignment statement is actually an implicit loop over observations. Beginning with the first observation in the sample, EViews will evaluate the assignment statement for each included observation.
Basic Assignment
You can type the series name, followed by an equal sign and then an expression. For every element of the sample, EViews will evaluate the expression on the right-hand side of the equality, and assign the value to the destination series on the left-hand side, creating the series if necessary.
For example, if there is no series named Y,
y = 2*x + 37*z
will first create the Y series and fill it with NAs. Then, for every observation in the current sample, EViews will fill each element of the Y series with the value of the expression. If Y does exist, EViews will only replace Y values in the current sample with the value of the expression. All observations not in the sample will be unchanged.
One special form of assignment occurs when the right-hand side of the assignment statement is a constant expression:
y = 3
y = 37 * 2 + 3
EViews will simply assign the value of the constant to all of the observations in the sample.
Using Samples
By modifying the sample of observations used in assignment, you can splice together series using multiple series assignment commands. For example, if we enter three assignment commands with different samples: first
Upper window: y = z
Lower window: @all if z<=1 and z>-1
followed by an assignment with,
Upper window: y = -2 + 3*z
Lower window: if z>1
and finally,
Upper window: y = -.9 + .1*z
Lower window: if z<=-1
we can generate Y as a piecewise linear function of the series Z. Note that the “@ALL” is implicit in the latter two assignments.
While it is possible to perform these types of operations using loops and IF-statements“EViews Programming”, we strongly urge you to use genr and sample statements where possible, since the latter approach is much more efficient.
Dynamic Assignment
Since EViews evaluates the assignment expression for each observation in the sample, you can perform dynamic assignment by using lagged values of the destination series on the right side of the equality. For example, suppose we have an annual workfile that ranges from 1945 to 1997. Then if we enter:
Upper window: y = y + y(-1)
Lower window: 1946 1997
EViews will replace the Y series with the cumulative sum of Y. We begin with 1946, since we do not want to transform the first value in the workfile. Then for each period, EViews will take the current value of Y and add it to the lagged value of Y. The assignment is dynamic because as we successively move on to the next period, the lagged value of Y contains the cumulative sum.
Note that this procedure destroys the original data. To create a new series with the cumulative sums, you will have to perform the assignment in two steps, first making a copy of the original series, and then performing the dynamic assignment.
Implicit Assignment
You can make an implicit assignment by putting a simple formula on the left-hand side of the equal sign. EViews will examine your expression and select, as the destination series, the first valid series name on the left-hand side of the equality. Then for every observation in the sample, EViews will assign values using the implicit relationship. For example, if you enter:
log(y) = x
EViews will treat Y as the destination series, and evaluate y=exp(x) for every observation in the sample.
The following are examples of valid assignment statements where Y is the destination series:
1/y = z
log(y/x)/14.14 = z
log(@inv(y)*x) = z
2+y+3*z = 4*w
d(y) = nrnd
In general, EViews can solve for, or normalize, equations that use the following on the left-hand side of the equality: +, –, *, /, ^, log(), exp(), sqr(), d(), dlog(), @inv().
Since Genr is not a general equation solver, there will be situations in which EViews cannot normalize your equation. You cannot, for example, use the assignment statement:
@tdist(y, 3) = x
since @tdist is not one of the functions that EViews knows how to invert. Similarly, EViews cannot solve for equations where the destination series appears more than once on the left side of the equality. For example, EViews cannot solve the equation:
x + 1/x = 5
In both cases, EViews will display the error message “Unable to normalize equation”.
Note that the destination series can appear on both sides of the equality. For example:
log(x) = x
is a legal assignment statement. EViews will normalize the expression and perform the assignment
x = exp(x)
so that X will be assigned the exponential of the original value of X. EViews will not solve for the values of X satisfying the equality “LOG(X) = X”.
Using the Command Window
You can create series and assign values from the command window. First, set the workfile sample using the smpl statement, then enter the assignment statement.
There are alternative forms for the assignment statement. First, if the series does not exist, you must use either the series or the genr keyword, followed by the assignment expression. The two statements:
series y = exp(x)
genr y = exp(x)
are equivalent methods of generating the series Y. Once the series has been created, subsequent assignment statements do not require the series or the genr keyword:
smpl @all
series y = exp(x)
smpl 1950 1990 if y>300
y = y/2
This set of commands first sets the series to equal EXP(X) for all observations, then assigns the values Y/2 for the subset of observations from 1950 to 1990 if Y>300.