### Introduction

Today we will help you to understand and resolve `Error G0025: Undefined symbol`

. We will answer the questions:

- What is a GAUSS symbol?
- What are the most common types of GAUSS symbols?
- How do I define a GAUSS symbol?
- How do I resolve the error
`G0025: Undefined symbol`

?

## What is a symbol?

In GAUSS a symbol is a label used to represent some data, a procedure or function. For example, in the code below:

```
a = 3;
b = 4;
```

`a`

and `b`

are symbols representing the scalar values 3 and 4 respectively.

```
c = a + b;
d = 3 + 4;
```

The above code creates two new symbols, `c`

and `d`

.

`c`

is created by applying the addition operator to the previously created symbols,`a`

and`b`

.`d`

is created by adding two literal values.

Numbers, such as the integers `3`

and `4`

are called *literals*, rather than *symbols*.

## How to define a symbol

**Numeric and string symbols** are defined in GAUSS using the equals sign as we saw previously. Here are some more examples:

```
// Define the symbol 'e' to be a 3x1 vector
e = { 2.1, 0.9, 3.8 };
// Define the symbol 'f' to be the
// largest element of the vector 'e'
f = maxc(e);
// Define the symbol 'g' to be a 10x2 random normal matrix
g = rndn(10,2);
// Define the symbol 'h' to be a string
h = "String symbols contain text";
```

**Procedure ( proc) and function (fn) names** are also symbols. Below are some simple examples of procedure definitions:

```
/*
** The procedure and function definitions below define the symbols
** 'doubleIt' and 'squareIt'.
*/
proc (1) = doubleIt(X);
retp(X .* 2);
endp;
fn squareIt(X) = X .^ 2;
```

## Basic undefined symbol examples

Any time a symbol is referenced on the right side of an equation before it has been defined can cause `Error G00025: Undefined symbol`

. Here are a few simple examples:

```
// Clear out all symbols in the GAUSS workspace
new;
// Since 'a' has not been defined,
// this line will cause an error
b = a;
```

```
// Clear out all symbols in the GAUSS workspace
new;
b = 3;
// Since 'a' has not been defined,
// this line will cause an error
c = a + b;
```

```
// Clear out all symbols in the GAUSS workspace
new;
a = { 2, 4, 6 };
// Since the procedure 'foo' has not been defined,
// this line will cause an error
X = foo(a);
```

## Solve a simple undefined symbols error

If we run a file named `estimate.gss`

with the following contents:

```
// Clear all symbols from the GAUSS workspace
new;
/*
** Simulate random normal variables
*/
X = rndn(nobs, nvars);
/*
** Simulate a random normal response variable
*/
y = rndn(nobs, 1);
/*
** Estimate a linear model
*/
call glm(y, X, "normal");
```

we will get the following error messages:

G0025 : Undefined symbol: 'nobs' [estimate.gss, line 6] G0025 : Undefined symbol: 'nvars' [estimate.gss, line 6]

These error messages tell us that line 6 of our code is using two symbols that have not yet been defined, `nobs`

and `nvars`

. To resolve these errors, we need to set those symbols to appropriate values.

The inputs to the `rndn`

function need to be scalar values that represent the number of rows and columns of the output matrix. We set them to 100 and 4 respectively in the code below to resolve the errors.

```
// Clear all symbols from the GAUSS workspace
new;
// Specify the number of observations to simulate
nobs = 100;
// Specify the number of columns to simulate
nvars = 4;
/*
** Simulate random normal variables
*/
X = rndn(nobs, nvars);
/*
** Simulate a random normal response variable
*/
y = rndn(nobs, 1);
/*
** Estimate a linear model
*/
call glm(y, X, "normal");
```

After these changes the code will run successfully.

## What causes undefined proc or function symbols?

Now let's move to a less obvious example. Let's suppose we have a file `arimafit-example.gss`

with these contents:

```
// Clear all symbols from GAUSS workspace
new;
// Create file name with full path
fname = getGAUSSHome() $+ "pkgs/tsmt/examples/enders_sim2.dat";
p = 3;
d = 1;
q = 1;
// Run arima estimation
call arimaFit(fname, "ar2", p, d, q);
```

When we run this file, we get the error:

G0025 : Undefined symbol: 'arimaFit' [arimafit-example.gss, line 12]

In this example, we can tell that `arimaFit`

is a GAUSS procedure or function. There are four main reasons why a procedure or function might be undefined in your GAUSS code:

### 1. It was added in a newer version of GAUSS than you have.

You can search the GAUSS Change Log for the procedure or function to see if it has been added in a newer version.

### 2. It is in a library that you do not have loaded.

`arimaFit`

from our above code snippet is from the GAUSS Time Series MT add-on package. If this is the case, you will need to make sure that the package is installed and loaded correctly.

Undefined references to the procedures `maxset`

, `optset`

, `maxlik`

and `optmum`

are sometimes found undefined in publicly available third-party code.

### 3. It is in a code file that GAUSS has not been told about.

Our Basics of GAUSS Procedures blog explains the four ways to tell GAUSS about your user-defined procedure.

### 4. Running the code line-by-line

When you run a file all at once, GAUSS allows you to place procedures wherever you like, such as the end of the file.

```
new;
a = 3;
b = doubleIt(a);
proc (1) = doubleIt(x);
retp(2 * x);
endp;
```

However, if you run a program file like the one above, line-by-line, you will get an undefined symbol error. If you run the entire file at once, GAUSS will search the file for any procedures that it does not know about. However, when you run the code line-by-line, GAUSS only runs the code you tell it to run.

You can resolve this problem, by either:

- Running the code under the debugger.
- Adding the procedures to a GAUSS library or a
`.g`

file. - Highlighting all lines of the needed procedures and running them first.

### Conclusion

Congratulations! In today's blog, you have learned that:

- GAUSS symbols are labels, or names, that represent data, procedures and functions.
- Use of a symbol on the right side of an equation before it is defined, or assigned a value, can cause an undefined symbol error.
- Symbols are commonly defined by using the equals operator as well as loading libraries.