Tutorial Eviews Programming PDF
Tutorial Eviews Programming PDF
Tutorial Eviews Programming PDF
EViews Programming
The EViews Command Language
2
The EViews Command Language
• Commands
• Functions
• Object Views and Procs
• Object Data Members
3
EViews Commands
4
EViews Commands: Container Manipulation
5
EViews Commands: Container Manipulation
6
EViews Commands: Container Manipulation
7
EViews Commands: Object Creation
8
EViews Commands: Object Creation
Often you can follow the command with further specification for the
object:
9
EViews Commands: Object
show/copy/rename/delete/close
10
EViews Functions
12
EViews Functions
Some examples:
series x = @log(y) Create a series, X, and assign the values of log(Y) to it.
series x = @pch(y) Assign the one-period percentage change in Y to X.
series x = @pv(r,n,y) Present value of Y, given a rate of R and N periods.
scalar x = @mean(y) Create a scalar, X, equal to the mean of Y.
series x = @cumsum(y) Cumulative sum of Y.
series x = @movav(y,3) Three period moving average of Y.
series x = @rsum(g) Row-sum of the group, G.
series x = @minsby(y,s) Minimum values of Y for each category of S.
!x = @tan(y) Assign the tangent of the program variable !y to !x.
scalar x = @cnorm(y) Cumulative normal distribution at value Y.
!x = @instr(%y, "he") Find the position of the phrase "he" in the string %y.
string x = @strnow Create a string object containing the current date/time.
series x = @trend Create a trend series. 13
Object Views and Procs
Each object view and proc has a command line equivalent. The
general syntax of object views and procs is:
object.view(options) arguments
i.e. the name of the workfile object, followed by a dot, then the
view/proc name, followed by options and any arguments.
The Views and Procs available to each object type are listed in the
EViews 9 Object Reference.
14
Object Views and Procs
Some examples:
show eq01.stats Show the regression output of the equation object EQ01.
show gdp.line Show a line graph of the series GDP.
freeze(gr1) gdp.line Freeze the graph of GDP into a new graph object, GR1.
eq01.forecast yf Forecast EQ01, storing the forecast values into series YF.
unemp.smooth unemps Exponential smoothing on UNEMP, and save to UNEMPS.
show gp.coint(s) Show the summary cointegration test results for group GP.
15
Object Data Members
Along with the Views and Procs available to each object type,
objects also contain "data members". These are retrievable
objects that contain information about the parent object.
=object.@member
16
Object Data Members
Data members are stored with the object. EViews, in general, does
not need to perform calculations to retrieve the members (unlike
Views and Procs).
Each object's data members are listed at the start of the object's
section of the EViews 9 Object Reference.
17
Object Data Members
Some examples:
=unemp.@displayname Returns the UNEMP series' display name.
=gdp.@first Returns the date of the first non-NA in GDP.
scalar x = eq01.@r2 Stores the R-squared from EQ01 into the scalar X.
matrix x = eq01.@coefcov Saves EQ01's coefficient covariance matrix into matrix X.
vector x = eq01.@tstats Saves the t-statistics into vector X.
=g1.@count Returns the number of series in the group G1.
=g1.@seriesname(1) Returns the name of the first series in the group G1.
18
EViews Program Basics
19
Creating a New Program
20
Loading and Saving Programs
21
Running a Program
Once you have created your program, you can run it by clicking on
the Run button.
22
A Simple Program
23
Program Comments
Example:
series x = @nrnd 'this is a comment
Only the "series x = @nrnd" part of this line is executed by EViews.
24
Program Variables
25
Program Variables
Program variables are variables that only exist when the program is
running. Once the program has finished, the variables disappear.
They do not form part of your workfile.
Examples:
!x = 3
!y = 3+2
!z = !x + !y
!pi = 4*@atan(1)
series y = @sqrt(!z)
27
% Variables
You can concatenate two strings with a + sign. You may also use
string functions to assign to a % variable.
Examples:
%x = "hello"
%y = "my name is" + %name
%pi = "3.142"
%z = "The date/time is " + @strnow
28
Replacement Variables
You can use % variables in two ways. The first is as an string actual
string – i.e. anywhere EViews expects a string value, you can use a
% variable instead.
29
Replacement Variables
Example:
%x = "gdp"
series y = %x
series z = {%x}
32
Program Arguments
If you enter "Y X" into the Program arguments box on the run dialog,
then the program will execute the line:
equation eq1.ls Y C X
33
Control of Execution
34
If/else/endif statements
If statements are used when you wish to execute a line of code only
if a certain condition is met. The basic syntax is:
if [condition] then
'line of code to execute
endif
35
If/else/endif statements
Examples:
if 1+1=2 then
wfcreate a 1990 2000
endif
Since 1+1 does equal 2, the wfcreate command will be executed
(creating an annual workfile between 1990 and 2000).
if !p>3 then
equation eq1.ls y c x1 x2
endif
Only if the program variable, !p, is greater than three will equation
EQ1 be estimated.
36
If/else/endif statements
if @max(sales)>1000000 then
show price.hist
endif
If the maximum value of SALES is greater than 1,000,000, show the
histogram and descriptive statistics of the series PRICE.
37
If/else/endif statements
38
If/else/endif statements
Example:
if !p>3 then
equation eq1.ls y c x1 x2 x3
else
equation eq1.ls y c z1 z2 z3
endif
If !p is greater than 3, equation Y is regressed against X1, X2 and
X3. Otherwise Y is regressed against Z1, Z2 and Z3.
39
If statements and series/samples
Examples:
smpl if x<0
series y = 100
smpl if x<=0
series y = 200
smpl @all
41
For Loops
Examples:
for !i=1 to 5
series x{!i} = @nrnd
next
This loop generates 5 random normal series, X1, X2, X3, X4 and
X5.
for !i=1 to 10
equation eq1.ls y c x{!i}
next
Five equations are created, each regressing Y against a single X
variable.
42
For Loops
You may optionally add a step statement to change how much the
control variable increases at each iteration of the loop:
for !i=1 to 10 step 2
series x{!i} = @nrnd
next
This loop generates 5 random normal series, X1, X3, X5, X7 and
X9.
String for loops simply loop a string control variable over different
string values.
44
For Loops
Examples:
for %j gdp unemp time
series {%j} = @nrnd
next
This loop generates 3 random normal series, GDP, UNEMP and
TIME.
46
Maximum Number of Errors
Example:
wfcreate m 1990 2000
series y=@nrnd
series x=@nrnd
series w=@nrnd
series z=3
for %reg x z w
equation eq_{%reg}.ls y c {%reg}
next
This program loops through the series X, Z and W, performing a
regression of Y against a constant and each of those series, one at
a time. It will cause an error when it regresses against Z, since Z is
perfectly collinear with the constant.
48
Maximum Number of Errors
50
Running/Executing Programs
51
Run Command
The Run command can be issued from the EViews command line
to instruct EViews to open and run a program. The syntax is:
run myprogram.prg [arguments]
Simply give the name of the program (with a path, if required)
following the Run command.
52
Run Command
For example:
53
Run Command
You may also use the Run command inside a program to launch
and run a second program.
For example:
54
Run Command
However, the Run command has one drawback when being used
inside a program: EViews will not return to the calling program
once the child program has finished running. For example:
In this program the line estimating equation eq2 will never execute.
EViews stops all program execution once run_monthly.prg has
finished.
55
Exec Command
The Exec command works in the same was as the Run command,
with one main differences; unlike the Run command, EViews will
continuing executing the calling program after an Exec.
56
Exec Command
Note that with the Exec command (and Run) each program's
program variables are isolated. i.e. setting a variable, such as !i, in
the parent program will not interfere with a variable with the same
name in the child program.
59
Subroutines
60
Subroutine Definition
61
Subroutine Definition
Example:
62
Calling Subroutines
63
Subroutine Arguments
64
Subroutine Examples
65
Subroutine and Argument Placement
66
Tips
• Subroutine should all be placed at the start of the program file for
easy debugging access.
• If you have many subroutines, define them in a separate program
file and then include that file at the top of your program.
• Define your subroutines such that outputs come first in the
argument list (or come last). Don't mix inputs and outputs.
• For even greater clarity, name the arguments with a name that
indicates whether the argument is an input or output.
67
Subroutine Strings and Scalars
Here foo uses workfile objects, and goo uses program variables
(note the use of % and ! in the argument names).
68
Subroutine Strings and Scalars
subroutine foo(scalar b)
subroutine goo(scalar !b)
call foo(myscalar)
call foo(!x)
call foo(3)
call goo(myscalar)
call goo(!x)
call goo(3)
69
Subroutine Strings and Scalars
70
Subroutine Strings and Scalars
For example the following program will error inside foo because the
scalar a is not available on the new page, so x cannot be created.
71
User Dialogs
72
User Dialogs
These custom dialogs (or User Dialogs to use the EViews term)
allow the program to present information, or collect information,
from the person running the program.
73
User Dialogs
74
User Dialogs
@uilist Produces a list box. @uilist(string iostring, string prompt, string list)
Has two versions, one @uilist(scalar ioscalar, string prompt, string list)
returns a string, the
other a scalar.
@uiradio Produces a set of radio @uiradio(scalar ioscalar, string prompt, string list)
buttons.
75
User Dialogs
All User Dialogs are EViews functions, and as such have return
values. The value returned depends upon whether the user clicked
on the "OK" button or the "Cancel" button.
If a user clicks "OK" on the User Dialog, the function will return a
value of 0. "Cancel" returns -1.
76
@uidialog
77
@uidialog
"radio" scalar ioscalar, string prompt, string list Set of radio buttons
79
EViews Add-ins
However, the most important thing about Add-ins (at least for this
class) is that Add-ins are really nothing more than EViews
programs.
Any program you write can be turned into an EViews Add-in, simply
by using the Manage Add-ins menu item.
80
Adding Add-ins
When you add an Add-in to your copy of EViews, you may specify
whether the Add-in is available via the menu system, via a
command, or both.
Global add-ins are available at all times, and always appear in the
Add-ins menu. Object-specific add-ins only appear in the Add-ins
menu when an object of that type is open.
81
addin
The problem is that you probably won't know the name of the
currently open object, so referencing the data-members, or
accessing views and procs of the currently open object could be
tricky.
83
_this
All of the object data members, procs and views are available by
using _this rather than the object's name.
Thus:
_this.hist will show a histogram of the current open object
(if the current open object is a series).
_this.@coefcov will access the equation's coefficient
covariance matrix (if the current open object is an equation).
84