Generating Data From a Linear Model
Step One: Start out in GAUSS
We will begin this exercise from the Command Page in GAUSS. Click the “Command” tab on the top left of the GAUSS user interface.
The Command Page in GAUSS provides a large program input/output window for entering interactive commands in GAUSS and seeing printed output.
Step Two: Clear the program input/output window and clear all variables from the workspace.
When starting a new project it is often desirable for your workspace to be a clean slate. You can accomplish this by entering two simple commands.
First, place your cursor in the program input/output window. To clear out any previously assigned variables from the workspace, enter:
Next, to clear any previously printed output from the screen enter:
cls is short for clear screen. Note that these two commands will clear all data from your work space and clear the input/output screen but will not erase your program files. You should now see these two commands in your command history under the italicized headed “Today”.
Step Three: Randomly generate ‘x’ data and the error term
Place your cursor at the GAUSS command-line again and enter:
x = rndn(500, 1);
Confirm that the matrix was created by entering:
The print keyword will print the output directly to the program input/output window.
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.
From the GAUSS command-line, enter:
err = 5 * rndn(500, 1);
Step Four: Generating ‘y’ data
Now to finish generating our data we need to specify the parameters of the model and generate y’s 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_0, b_1, x, and err by entering the following statement on the command line:
y = b_0 + b_1*x + err;
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.
Step Five: 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.
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”.
You will automatically be taken to an untitled program file located on the Source Page. You will see all the commands copied to a program file named untitled.gss.
Save and name the file by selecting “File->Save As…” from the main application menu at the top of the application.