Command Reference : EViews Programming : Simple Programs
Simple Programs
The simplest program is just a list of EViews commands. Execution of the program is equivalent to typing the commands one-by-one into the command window.
While you may execute the commands by typing them in the command window, you could just as easily open a program window, type in the commands and click on the Run button. Entering commands in this way has the advantage that you can save the set of commands for later use, and execute the program repeatedly, making minor modifications each time. (Note that you may combine the two methods by entering the commands in the command window and then save them to a file as described in “Saving the Command Window”.)
Since an EViews program is a collection of commands, familiarity with the EViews command language is an essential part of programming. The command language may be split into four different groups in EViews.
General commands create, structure and manipulate workfiles (including importing and exporting data) and create workfile objects. These commands are listed in “Command Reference”.
Object commands execute views and procedures on objects in the workfile (such as series, groups and equations).
For example, unit root tests are done via a series command (series.uroot), co-integration tests are a group command (group.coint), and regression and forecasting are performed via equation commands ( and equation.forecast). The full set of object commands can be found in “Object View and Procedure Reference”, where they are listed by object type.
Functions may be used to create new data, either in the form of workfile objects or as program variables.
Creating a new series that is equal to the moving average of an existing series is done with the @movav function. The @rbinom function is used to generate a random scalar or series from the binomial distribution. @pagefreq may be used to generate a string object or program variable containing the frequency of the current workfile page. In general, functions all start with the @ symbol.
Listings of the available @-functions available can be found in (here)19 ( “Operator and Function Reference”, “Operator and Function Listing”, “Workfile Functions”, “Special Expression Reference”, “String and Date Function Reference”, “Matrix Language Reference”, and “Programming Language Reference”).
Object data members allow you to retrieve a fundamental piece of data from an object. Unlike object commands that execute a view or procedure on an object, data members merely provide access to existing results. Data members almost all start with an @ symbol and can be accessed by typing the name of the object followed by a “.” and the name of the data member.
For example, eq1.@coefs returns a vector containing the estimated coefficients from the equation object EQ1. ser01.@last returns a string containing the date (or observation number) of the last non-NA value in the series SER01. The list of data members available for each object is listed in the object’s section of “Object View and Procedure Reference”.
Let’s examine a simple example (the data series are provided in the database PROGDEMO in your EViews directory so that you can try out the program). Create a new program by typing
program myprog
in the command window. In the program window that opens for MYPROG, we are going to enter the commands to create a workfile, fetch a series from an EViews database named PROGDEMO, run a regression, compute residuals and a forecast, make a plot of the forecast, and save the results.
' housing analysis
wfcreate(wf=myhouse) m 1968m3 1997m6
fetch progdemo::hsf
smpl 1968m5 1992m12
equation hsf c hsf(-1)
reg1.makeresid hsfres
smpl 1993m1 1997m6
reg1.forecast hsffit
freeze(hsfplot) hsffit.line
The first line of the program is a comment, as denoted by the apostrophe “'”. In executing a program, EViews will ignore all text following the apostrophe until the end of the line.
The line containing the wfcreate command creates a new workfile, called MYHOUSE, with a monthly frequency spanning the dates March 1968 to June 1997. A series called HSF (total housing units started) is fetched from the database PROGDEMO. The rest of the program results in a saved workfile named MYHOUSE containing the HSF series, an equation object REG1, residual and forecast series HSFRES and HSFFIT, and a graph HSFPLOT of the forecasts.
You can run this program by clicking on Run and filling in the dialog box.
Now, suppose you wish to perform the same analysis, but for the S&P 500 stock price index (FSPCOM). Edit the program, changing MYHOUSE to MYSP500, and change all of the references of HSF to FSPCOM:
' s&p analysis
wfcreate(wf=mysp500) m 1968m3 1997m6
fetch progdemo::fspcom
smpl 1968m5 1992m12
equation fspcom c fspcom(-1)
reg1.makeresid fspcomres
smpl 1993m1 1997m6
reg1.forecast fspcomfit
freeze(fscomplot) fspcomfit.line
Click on Run to execute the new analysis. Click on the Save button to save your program file as MYPROG.PRG in the EViews directory.
Since these two programs are almost identical, it seems inefficient to have two separate programs for performing the analysis. In “Program Arguments” we describe a method for performing these two forecasting problems using a single program. First however, we must define the notion of program variables that exist solely when running programs.