go to Trig home page   Guide to GAUSS Programming - a basic introduction


 
Introduction

1. What is GAUSS?

GAUSS is a programming language designed to operate with and on matrices. It is a general purpose tool. As such, it is a long way from more specialised econometric packages. On a spectrum which runs from the computer language C at one end to, say, the menu-driven econometric program EViews at the other, GAUSS is very much at the programming end.

Using GAUSS thus calls for a very different approach to other packages. Although a number of econometric add-ons have been written (for example, ML-GAUSS, a suite of maximum likelihood applications), you will rarely be able to "turn up and go" with GAUSS. More often than not, getting useful results from GAUSS requires thought, a systematic approach, and usually a little time.

Having said that, the thought required is often no more than a recognition of what precisely you are trying to achieve. The GAUSS operators and the standard library functions are designed to work with matrices. This means that if you can write down the operations you want to perform, the chances are that they can be translated directly into a line in your program. The statement "β=(X'X)-1X'y" is acceptable to GAUSS with only minor changes.

1.1 Advantages
  • GAUSS is appropriate for a wider range of applications than standard econometric packages because it is a general programming language.
  • GAUSS operates directly on matrices. This makes it more useful for economists than standard programming languages where the basic data units are all scalars.
  • GAUSS programs and functions are all available to the user, and so the user is able to change them. If you dislike a heteroscedasticity test in a commercially produced package, you may be able to a new routine and replace the old procedure with your own.
  • Similarly, if data is held in a non-standard format, you may write your own routine to access it.
  • GAUSS is extremely powerful for matrix manipulation. It is also fast and efficient.
1.2 Disadvantages
  • The fixed costs of using GAUSS are high. Its very generality means that there is unlikely to be a simple procedure to do a simple econometric task readily to hand (although commercially available routines ameliorate this somewhat).
  • Even if pre-programmed or bought in software is available for a task, a reasonable degree of familiarity with GAUSS and its methods will often be necessary to make effective use of such routines.
  • GAUSS is too tolerant of sloppy programming. GAUSS is very flexible; however, this means it is difficult for the computer to tell when mistakes occur. For example, lax conformability requirements mean that it is easy to mistakenly divide a scalar by a row vector and then multiply by a matrix in the belief that all three variables were column vectors.
  • GAUSS is not tolerant of errors in its environment. Ask it to read from a non-existent file, or use an uninitialised variable, and the program stops. This is, of course, a sensible feature of all programming languages. Unfortunately, GAUSS is short on routines allowing non-fatal error checking.
  • Input and output routines are basic - especially input.
  • GAUSS programs are designed to be run within the GAUSS environment. They cannot be run as stand-alone programs (.EXE files) without buying a program called the GAUSS "Run-time Engine"TM. Thus you can only swap code with other GAUSS users.
1.3 When to use GAUSS

GAUSS is ideally suited to non-standard tasks. For example, we have developed programs to analyse and do estimates on data which comes in the form of cross-product matrices. Alternatively, you may wish to vary or add to standard techniques; for example, adding a new estimator.

If the core of your task is matrix manipulation in any way, then GAUSS is likely to be a better bet than a full programming language. Its primitive I/O facilities are offset by the processing capability. However, GAUSS is not appropriate for, say, writing a menu system; a general-purpose language is probably easier.

Nor is GAUSS appropriate for standard applications on standard datasets. There is little point in writing a probit estimation routine in GAUSS for a small dataset. Firstly, there are already routines commercially available for non-linear estimation using GAUSS. More importantly, TSP, LimDep, etc will already perform the estimation and there is no necessity to learn anything at all about GAUSS to use these programs. However, to get extra specification tests, for example, a straightforward solution would be to code a routine and emend the preexisting GAUSS probit program to call the new procedure at the appropriate point in its working.


 
2. Platforms and interfaces

GAUSS is available in both single user versions and networked versions. From the user's perspective, the main difference is that you may have less control over your environment in a network setting, but otherwise the versions are the same. For the system administrator, the network version simplifies license and user management, particularly for shared machines.

2.1 GAUSS on a PC

GAUSS for PCs now comes as a Windows application. However, for those wanting to use the old DOS-based interface a program called TGAUSS.exe is included with the distribution. There appears to be a negligible speed difference between the two except for programs displaying a lot of information on the screen.

2.2 GAUSS on Unix/Linux

GAUSS on Unix is very powerful and very quick, partly because Unix machines are designed for heavy-duty processing and computation rather than user interaction. For manipulating large matrices, the time saving can be tremendous.

GAUSS on Unix runs in both teletype (command-line) and X-Windows mode. Access to the latter depends on how you access your Unix machine.

There is also a version to run on Linux (a form of Unix which runs on Intel processors). For simplicity, this guide will not distinguish bewtween Unix and Linux.

2.3 Memory management

In the early days of GAUSS, efficient memory management was often crucial to getting a program running well. The amount of memory used by GAUSS could be varied by the user to make appropriate use of scarce resources. However, this is much less of an issue in modern computers, and from version 4.0 for Windows, GAUSS no longer gives you the option to manage memory directly. Instead it relies on the more efficient memory-management facilities of the operating system.

This does not mean you may ignore the issue of effective programming skills. It is suprisingly easy to run out of memory when doing complex operations on large matrices. For a more detailed discussion see the section on code refinements.

2.4 Interfaces

GAUSS programs can be written in two ways:
  • command-line
    In this mode, commands typed into the GAUSS interface are executed immediately. This allows for an instant response to a command, but the commands cannot be stored. This is therefore not suitable for writing large programs, or for commands which need to be run repeatedly.
  • batch or program
    In this mode, GAUSS commands are typed into a text file. This file is then sent to be GAUSS to be run. This allows one to develop and store complex programs.
This facility has existed since the earliest versions of GAUSS. However, the precise way this is carried out has varied over time. The original DOS interface is still extant in the latest Windows version as "TGAUSS", but the recommended interface is the windowing one. The Unix version is closer to the DOS version but has a few operating differences. Additionally, all three versions draw graphics windows differently as a result of their operating environments.

However, the practical differences between versions of GAUSS on various operating systems are minimal. The GAUSS code covered in this guide should be universally applicable. Thus there is no section of the guide concentrating on the interfaces. At the moment, I suggest you refer to the manual for your particular version. The forthcoming book An Introduction to GAUSS for economists includes short movies about using the Windows interfaces.


3. Notation and layout

GAUSS is not case-sensitive. However, throughout the guide capitals will be used for 'reserved words' and standard GAUSS functions. The names of all variables are lower case, with capital letters separating words. Procedures will be identified by an initial capital. All this makes no difference to GAUSS; it just makes life easier (see section on Writing for posterity). Italics will be used to indicate a value to be substituted.

Where a constant is mentioned, this means an actual number or character set. Values are the results of some operation. Where a constant is required, a constant must be supplied; but where a value is required either a constant or a value is acceptable. Constant-list and value-list are lists of constants or values, separated by spaces or punctuation marks. The type of separator may affect the result of the operation.

3.1 Examples

Naming conventions
LET GAUSS reserved word
DELIF GAUSS standard procedure
Process user-defined procedure
FindFile user-defined procedure
mat1 variable
fileName variable

Constants
a  "a"  27  "ok"  -0.0062  5.3E+2

Invalid constants
a*b  c-27

Constant-lists
a b c d e
a, b, c,
"a", "b", "c"
1,2,3,4.5,6.7,8
1 2 3 4.5 6.7 "hello" 8

values
a  "a"  a*b  b+a  "ok"  5.3*102  5.3E+2  -27*(63+5)

value-lists
a*b,  b*c,  c*a
a*b  25  b*c  "hello"  c*a

Note that, when constants are expected, a string constant (a piece of text) may or may not be enclosed in quotation marks. It makes no difference to GAUSS, other than to make errors more likely. By contrast, when a value is expected, a string without quotation marks will be treated as a variable the current value of which is to be used. To try to avoid this confusion, this coursebook will place string constants in quotation marks; strings with no quotation marks will be variables.

For large numbers we use GAUSS's scientific notation standard; that is 5,720 can be written as 5.72E+3 (5.72 x 103) and 0.05 as 5.0E-2 (5.0 x 10-2).

3.2 Layout and Syntax

GAUSS could be described as a free-form structured language: structured because GAUSS is designed to be broken down into easily-read chunks; free-form because there is no particular layout for programs. Although the syntax is closely defined, extra spaces between words (including line breaks) are ignored. Commands are separated by a semi-colon, rather than having one command on each line as in FORTRAN or BASIC. A complete instruction is identified by the placing of semicolons, and not by the placing of commands on different lines.

Program layout is generally a matter of supreme indifference to GAUSS, and this gives the user freedom to lay out code in a style he finds acceptable. For example, the conditional branching operation IF could be written

IF condition; action1; ELSE; action2; ENDIF;

but equally acceptable to GAUSS would be

IF condition;
action1;
ELSE;
action2;
ENDIF;
or
IF condition; action1;
ELSE; action2; ENDIF;
or
IF condition;
action1;
ELSE;
action2;
ENDIF;

The coursebook will use the leftmost of these formats, but this is a matter of personal choice and users may wish to develop their own style. More will be made of this in Writing for posterity.

There are some exceptions to the rule that layout does not matter. Obviously, there cannot be extraneous spaces within words or numbers: 'I F', 'var 1' and '27 000' are not the same as 'IF', 'var1' and '27000'. In more recent versions of GAUSS spaces within mathematical expressions are not allowed in certain places, although this does not seem to be consistently enforced - for example, when entering expressions on the command line.

The other place where spacing is important is in comments:

/* this is a comment */

Anything within the /*...*/ markers is ignored by the program. However, there must not be a space between the slash and the asterisk, or the program will not recognise a comment marker and will erroneously try to analyse the contents of the comment block.


4. Using GAUSS

GAUSS in common with many other programs, will take instructions either from a file or from the command line. To start GAUSS:
  • in Windows, start GAUSS from the start menu list of programs
  • in Unix, type "gauss"
  • for TGauss, either use the window start menus, or, in an MS-DOS box, go to the GAUSS directory and type "tgauss". GAUSS 4.0 for Windows also installs a desktop icon which you can click on.
In all cases, GAUSS is operating in a command line mode. As each instruction is typed in, it is executed. A semi-colon is not necessary at the end of each line, although if you want to put several instructions on a line you will need to separate them with semicolons. GAUSS will carry out the instruction immediately.

To exit GAUSS, either close the window or type "QUIT" or "SYSTEM".

Command-line mode is fine for testing a few instructions, but for anything more than a couple of lines of code it is more sensible to operate in batch mode. In this case, you type the instructions into a separate text file, and then tell GAUSS to run the instructions in one go (a batch) with the command

RUN fileName

This will execute all the instructions in the file fileName in sequence. The results are, in theory, identical, whether the commands are in a file or typed in one at a time. The choice of when to work at the command line and when to place instructions in a file depends on the problem at hand; however, for more than a couple of lines of code, working in a file is usually easier.
Specific instructions as to how to edit and save text files depend upon your operating system. In the rest of this guide "program" will refer to any self-contained body of code we are working on, and you will find it easier to write the programs in separate files.

You can run programs directly without having to load GAUSS. At the Unix prompt, for example, entering

gauss fileName

will load GAUSS and run the program automatically. Under Windows, enter GAUSS or TGAUSS to load and run the Windows or non-Windows version. If you do not include either SYSTEM or QUIT and then end of our program then when the program has finished it will leave you in the GAUSS environment.

4.1 The help system: a warning

GAUSS has two electronic help systems, corresponding to the manuals. The "Command Reference" is an easy way to pick up information on commands (as long as they are not deemed "obsolete"), and is organised both alphbetically and by function, which is useful. It is very terse and does not display properly, but generally seems accurate.

The "User Guide" is slightly more chatty, and has more examples. Note however that it is less reliable. First, information on old commands is left unchanged, even though the commands may operate in a different way in later versions or has been deleted altogether. Second, information on new functions is often not forthcoming in that version. The first problem does seem to be disappearing, but if something doesn't work as the manual says it should, don't assume that it's your code that's wrong.

[ previous page ] [ next page ]