Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
EViews Guides BITCH / EViews_Illustrated.pdf
Скачиваний:
243
Добавлен:
03.06.2015
Размер:
13.69 Mб
Скачать

Chapter 16. Get With the Program

EViews comes with a built-in programming language which allows for very powerful and sophisticated programs. Because the language is very high level, it’s ideal for automating tasks in EViews.

Hint: Because EViews’ programming language is very high-level, it’s not very efficient for the kind of tasks which might be coded in C or Java.

Hint: To become a proficient author, you read great literature. In the same vein, to become a skilled EViews programmer you should read EViews programs. EViews ships with a variety of sample programs. You can find them under Help/Quick Help Reference/Sample Programs & Data. Appendix: Sample Programs at the end of these chapters includes several of the sample programs with annotations.

I Want To Do It Over and Over Again

If you have repetitive tasks, create an EViews program and run it as needed. EViews programs are not objects stored in the workfile. You don’t make them with Object/New Object…. An EViews program is held either in a program window created with File/New/Program or in a text file on disk ending with the extension “.prg”.

Hint: Clicking the button in a program window saves the file to disk with the extension “.prg”. But you’re free to create EViews programs in your favorite text editor or any word processor able to save standard ASCII files.

The program window at the right holds three standard commands. Every time you click these three commands are executed.

382—Chapter 16. Get With the Program

Hint: If you choose the Quiet radio button in the Run Program dialog (not shown here; see below), programs execute faster and more peacefully. But Verbose is sometimes helpful in debugging.

As a practical matter, you probably don’t want to run the same regression on the same series over and over and over. On the other hand, you might very well want to apply the same data transformation to a number of different data sets. For example, the Current Population Survey (CPS) records various measures of educational attainment, but doesn’t provide a “years of education” variable. The program “transformcps_ed.prg” translates the series A_HGA that appears in the data supplied in the CPS into years of education, ED. When new CPS data are released each March, we can run transformcps_ed again to re-create ED.

Documentary Hint: It’s sometimes important to keep a record of your analysis. While you can print lines typed in the command pane, or save them to disk as “COMMAND.log”, point-and-click operations aren’t recorded for posterity. Entering commands in a program and then running the program is the best way to create an audit trail in EViews.

Documentation Hint: Anything to the right of an apostrophe in a program line is treated as a comment. Writing lots of comments will make you happy later in life.

You Want To Have An Argument

You might want to run the same regression over and over again on different series. Our first program regressed LNWAGE on ED and then looked to see if there is a relation between the squared residuals and ED. Suppose we want to execute the same procedure with AGE and then again with UNION as the right-hand side variable.

Program Variables—383

Instead of writing three separate programs, we write one little program in which the right-hand side variable is replaced by an evaluated string variable argument. In an EViews program:

A string variable begins with a “%” sign, holds text, and only exists during program execution. You may declare a string variable by entering

the name, an equal sign, and then a quote delimited string, as in:

%y = "abc"

EViews automatically defines a set of string variables using arguments passed to the program in the Program arguments (%0 %1…) field of the Run Program dialog. The string variable %0 picks up the first string entered in the field. The string variable %1 picks up the second string. Etc.

You may refer to a string variable in a program using its name, as in “%Y”. EViews will replace the string value with its string contents, “ABC”. In some settings, we may be interested, not in the actual string variable value, but rather in an object named “ABC”. An evaluated string is a string variable name placed between squiggly braces, as in “{%0}”, which tells EViews to use the name, names, or name fragment given by the string value.

For example, if we enter “age” in the Run Program dialog, EViews will replace “{%0}” in the program lines,

ls lnwage c {%0}

series e = resid

ls e^2 c {%0}

and then execute the following commands:

ls lnwage c age

series e = resid

ls e^2 c age

If we had entered UNION in the dialog, the regressions would have been run on UNION instead of AGE.

Program Variables

String variables live only while a program is being executed. They aren’t stored in the workfile. While they live, you can use all the same string operations on string variables as you can on an alpha series.

384—Chapter 16. Get With the Program

Hint: A string variable in a program is a single string—not one string per observation, as in an alpha series.

Hint: If you want to keep your string after the program is executed and save it in the workfile, you should use put it into a string object.

In addition to string variables, programs also allow control variables. A control variable holds a number instead of a string, and similarly lives only while the program is alive. Control variables begin with an “!” as in “!I”.

Hint: And if you want to keep your number after the program is executed and save it in the workfile, you should use put it into a scalar object.

String and control variables and string and scalar objects can be defined directly in a program.

Hint: When read aloud, the exclamation point is pronounced “bang,” as in “bang eye.”

We’ve written a slightly silly program which runs four regressions, although the real purpose is to illustrate the use of control variables. Running this program is equivalent to entering the commands:

smpl if fe=0 ls lnwage c ed smpl if fe=1 ls lnwage c ed smpl if fe=0

ls lnwage c age smpl if fe=1

ls lnwage c age

Соседние файлы в папке EViews Guides BITCH