Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Eviews5 / EViews5 / Docs / EViews 5 Command Ref.pdf
Скачиваний:
82
Добавлен:
23.03.2015
Размер:
5.23 Mб
Скачать

Chapter 6. EViews Programming

EViews’ programming features allow you to create and store commands in programs that automate repetitive tasks, or generate a record of your research project.

For example, you can write a program with commands that analyze the data from one industry, and then have the program perform the analysis for a number of other industries. You can also create a program containing the commands that take you from the creation of a workfile and reading of raw data, through the calculation of your final results, and construction of presentation graphs and tables.

If you have experience with computer programming, you will find most of the features of the EViews language to be quite familiar. The main novel feature of the EViews programming language is a macro substitution language which allows you to create object names by combining variables that contain portions of names.

Program Basics

Creating a Program

A program is not an EViews object within a workfile. It is simply a text file containing EViews commands. To create a new program, click File/New/Program. You will see a standard text editing window where you can type in the lines of the program. You may also open the program window by typing program in the command window, followed by an optional program name. For example

program firstprg

opens a program window named FIRSTPRG. Program names should follow standard EViews rules for file names.

A program consists of a one or more lines of text. Since each line of a program corresponds to a single EViews command, simply enter the text for each command and terminate the line by pressing the ENTER key.

If a program line is longer than the current program window, EViews will autowrap the text of the line. Autowrapping alters the appearance of the program line by displaying it on multiple lines, but does not change the contents of the line. While resizing the window will change the autowrap position, the text remains unchanged and is still contained in a single line.

If you wish to have greater control over the appearance of your lines, you can manually break long lines using the ENTER key, and then use the underscore continuation character

84—Chapter 6. EViews Programming

“_” as the last character on the line to join the multiple lines. For example, the three separate lines

equation eq1.ls _

y x c _

ar(1) ar(2)

are equivalent to the single line

equation eq1.ls y x c ar(1) ar(2)

formed by joining the lines at the continuation character.

Saving a Program

After you have created and edited your program, you will probably want to save it. Press the Save or SaveAs button on the program window toolbar. When saved, the program will have the extension .PRG.

Opening a Program

To load a program previously saved on disk, click on File/Open/Program..., navigate to the appropriate directory, and click on the desired name. Alternatively, from the command line, you may type open followed by the full program name, including the file extension

.PRG. By default, EViews will look for the program in the default directory. If appropriate, include the full path to the file. The entire name should be enclosed in quotations if necessary. For example:

open mysp500.prg

open "c:\mywork is here\eviews\myhouse.prg"

opens MYSP500.PRG in the default directory, and MYHOUSE.PRG in the directory “C:\MYWORK IS HERE\EVIEWS”.

Executing a Program

When you enter, line by line, a series of commands in the command window, we say that you are working in interactive mode. Alternatively, you can type all of the commands in a program and execute or run them collectively as a batch of commands. When you execute or run the commands from a program, we say that you are in program (non-interactive) mode.

Program Basics—85

There are several ways to execute a program. The easiest method is to execute your program by pushing the Run button on a program window. The Run dialog opens, where you can enter the program name and supply arguments.

You may use the radio buttons to choose between Verbose and Quiet modes. In verbose mode, EViews sends messages to the status line and continuously updates the workfile window as objects are created and deleted. Quiet mode suppresses these updates, reducing the time spent writing to the screen.

If the checkbox labeled Version 4 compatible variable substitution and program boolean comparisons is selected, EViews will use the variable substitution behavior and boolean comparison methods found in EViews 4 and earlier. To support the use of alpha series, EViews 5 has changed the way that % substitution variables are evaluated in expressions. To return to EViews 4 compatible rules for substitution, you may either use this checkbox or include a “MODE VER4” statement in your program. See “Version 5 Compatibility Notes” on page 93 and “Program Modes” on page 97 for additional discussion.

By default, when EViews encounters an error, it will immediately terminate the program and display a message. If you enter a number into the Maximum errors before halting field, EViews will continue to execute the program until the maximum number of errors is reached. If there is a serious error so that it is impractical for EViews to continue, the program will halt even if the maximum number of errors is not reached. See “Handling Execution Errors” on page 107.

You may also execute a program by entering the run command, followed by the name of the program file:

run mysp500

or

run c:\eviews\myprog

The use of the .PRG extension is not required since EViews will automatically append one. The default run options described above are taken from the global settings, but may be overridden using command options or program options.

For example, you may use the “v” or “verbose”options to run the program in verbose mode, and the “q” or “quiet” options to run the program in quiet mode. If you include a

86—Chapter 6. EViews Programming

number as an option, EViews will use that number to indicate the maximum number of errors encountered before execution is halted. Any arguments to the program may be listed after the filename:

run(v, 500) mysp500

or

run(q) progarg arg1 arg2 arg3

Alternatively, you may modify your program to contain program options for quiet and verbose mode, and for setting version compatibility.

You can also have EViews run a program automatically upon startup by choosing File/Run from the menu bar of the Windows Program Manager or Start/Run in Windows and then typing “eviews”, followed by the name of the program and the values of any arguments. If the program has as its last line the command exit, EViews will close following the execution of the program.

See “Multiple Program Files” on page 108 for additional details on program execution.

Stopping a Program

Pressing the ESC or F1 keys halts execution of a program. It may take a few seconds for EViews to respond to the halt command.

Programs will also stop when they encounter a stop command, when they read the maximum number of errors, or when they finish processing a file that has been executed via a run statement.

If you include the exit keyword in your program, the EViews application will close.

Simple Programs

The simplest program is just a list of commands. Execution of the program is equivalent to typing the commands one by one into the command window.

While you could 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.

Let us look at 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

Simple Programs—87

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

workfile myhouse m 1968m3 1997m6 fetch progdemo::hsf

smpl 1968m5 1992m12

equation reg1.ls hsf c hsf(-1) reg1.makeresid hsfres

smpl 1993m1 1997m6 reg1.forecast hsffit freeze(hsfplot) hsffit.line save

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.

HSF is total housing units started. We end up with a saved workfile named MYHOUSE containing the HSF series, an equation object REG1, a 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

workfile mysp500 m 1968m3 1997m6 fetch progdemo::fspcom

smpl 1968m5 1992m12

equation reg1.ls fspcom c fspcom(-1) reg1.makeresid fspcomres

smpl 1993m1 1997m6 reg1.forecast fspcomfit

freeze(fscomplot) fspcomfit.line save

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.

Соседние файлы в папке Docs