INTRODUCTION

Simulated data can be very useful for testing models, function, and program files. In this tutorial we will be use GAUSS random number generators and matrix operations to simulate linear data:

 

 

For this exercise, let’s work from the GAUSS command line.

 

GAUSS Command Page.

The Command Page in GAUSS provides a large Program Input/Output Window for entering interactive commands in GAUSS and seeing the printed output.

 

CLEANING UP THE WORKSPACE

Our first step is to clean up the workspace and screen. A clean workspace helps to ensure that previously used data matrices don’t interfere with our current work. First, place your cursor in the program input/output window. To clear out any previously assigned variables from the workspace, enter:

 

new;

 

Next, to clear any previously printed output from the screen enter:

 

cls;

 

You should now see these two commands in your Command History Window under the italicized heading, Today.

 

GAUSS interactive commands.

Note: cls is short for clear screen. Note that these two commands will clear all data from your workspace and clear the input/output screen but will not erase your program files.

 

RANDOMLY GENERATING DATA

Now that we have a clean workspace we will generate our x data using the GAUSS rndn function. The GAUSS function rndn generates normally distributed numbers. You can change the variance (standard deviation) by multiplying the standard normal numbers by the desired variance. 

 

Place your cursor at the GAUSS command-line again and enter:

 

x = rndn(500, 1);

 

Confirm that the matrix was created by entering:

 

print x;

 

© 2024 Aptech Systems, Inc. All rights reserved.

 

The print keyword will print the output directly to the Program Input/Output Window.

 

From the GAUSS command-line, enter:

 

err = 5 * rndn(500, 1);

 

SIMULATING THE y DATA

Now to finish generating our data we need to specify the parameters of the model and generate the dependent data according to the model specified above:

 

 

 

Create a new 1×1 matrix b_0 set equal to 2 by entering the following statement on the command line:

 

b_0 = 2;

 

Create a new 1 x 1 matrix b_1 set equal to 3.5 by entering the following statement on the command line:

 

b_1 = 3.5;

 

Create the matrix y using the previously created b_0b_1x, and err by entering the following statement on the command line:

 

y = b_0 + b_1*x + err;

 

Note: In the statement above the operator * multiplies every value in the 500×1 matrix x by the value in the 1×1 matrix b_1. This occurs anytime one of the two variables is a scalar. If both variables are matrices then the operator * performs matrix multiplication.

 

CREATING A PROGRAM FILE 

All the steps above were performed in the command window. However, it is easy to use the Command History Window to copy these actions into a program file. This program file can be saved and used later to run this code again.

 

Send command history to a program file.

Figure 3: Sending multiple commands to a new program file.

 

Use the mouse to select the commands that you wish to copy to a program file. You may click-and-drag, or hold down the SHIFT button or the CTRL button to and select the desired files with your mouse.

 

Once you have selected the files, hold your mouse over the files and right-click to bring up a context menu. From the context menu, select Send to File.

 

CONCLUSION

Congratulations! In this tutorial you have learned how to:

  • Clear the screen and workspace.
  • Generate random data.
  • Use matrix operations to simulate data.
  • Create a program file using the command line history