Gauss Commands

Replace words in italics with file paths/names, variables, or values. The character | separates lists of options.

Command / Explanation / Example
@ / Precedes and follows a comment. Gauss will ignore everything between two @ symbols. / @ This is a comment. @
; / Each line in a Gauss program must end with a ; character. The character is not required when entering commands directly. / load x[3,4] = “a:/data.txt”;
y=x’x;
print y;
output file = “filename” on|off|reset / Opens an output file. The ON option creates the file if it doesn’t exist and appends output to the file if the file already exists. The OFF option closes the file. If you do not issue the OFF command, you may lose output that is stored in the output buffer but not yet written to the file. The RESET option creates the file if it doesn’t exist and overwrites the file if the file already exists. After turning on (or resetting) an output file, all “print” commands send data to both the screen and the printer. / output file = “a:/data/results.txt” reset
Note: Gauss uses linux notation for directory paths. Use forward slash instead of back slash.
print object / Prints to the screen or a file. / print “x”
Prints the character “x”
print x
Prints the value of the variable x.
load matrix[r,c] = “filename” / Reads data from a text file into a matrix that is r rows by c columns. / load x[3,4] = “a:/data.txt”
Note: Gauss uses linux notation for directory paths. Use forward slash instead of back slash.
save matrix / Saves matrix to the filename matrix.fmt / save x
xlsreadm(“filename”, “range”, sheet) / Reads data from an Excel file into a matrix. Range is the range of cells containing the data. Sheet is the number of the sheet within the workbook. / x = xlsreadm(“a:/data.xlsx”,“a1:d20”,1)
matrix = {x11 x12, x21 x22, x31 x32} / Creates a matrix of numbers. Spaces separate columns. Commas separate rows. / x = {1 5 7, 9 4 2, 4 4 8, 4 2 4}
creates the matrix
matrix’ / Transposes a matrix. / If x = then y’ =
ones(r, c) / Creates an r x c matrix of ones. / x = ones(4,3)
creates the matrix
zeros(r, c) / Creates an r x c matrix of zeros. / x = zeros(4,3)
creates the matrix
eye(n) / Creates an n x n identity matrix. / x = eye(3)
creates the matrix
inv(matrix) / Inverts a matrix. The matrix must be square. / If x = , then
inv(x) =
diag(matrix) / Extracts the diagonal from a square matrix. / If x = , then
diag(x) =
diagrv(matrix, vector) / Inserts the elements in vector into the diagonal of matrix. / If x = and y = then
diagrv(x,y) =
meanc(matrix) / Returns the means of the columns of matrix.
stdc(matrix) / Returns the standard deviations of the columns of matrix.
show matrix / Shows the dimensions of matrix. / show x
new / Clears variables from memory. / new
cls / Clears the output screen. / cls
* / Multiplies two matrices. The number of columns in the first matrix must equal the number of rows in the second matrix.
Note: When pre-multiplying by a transformed matrix, you can omit the * symbol. Example: x’y instead of x’*y / If x = and y = , then x*y =
+ / Adds two matrices. The numbers of rows in the two matrices must be the same and the number of columns in the two matrices must be the same. / If x = and y = , then x+y =
- / Subtracts two matrices. The numbers of rows in the two matrices must be the same and the number of columns in the two matrices must be the same. / If x = and y = , then x-y =
.*. / Kronecker multiplies two matrices. / If x = and y = , then x.*.y =
.* / Hadamard multiplies ʘ two matrices. Hadamard multiplication is element-by-element multiplication. / If x = and y = , then x.*y =
./ / Element-by-element division. / If x = and y = , then x./y =
~ / Column-wise concatenation. / If x = and y = , then
x~y =
| / Row-wise concatenation. / If x = and y = , then
x|y =
matrix[r1:r2, c1:c2] / Extracts a portion of a matrix. / If x = , then
x[1:2,3:3] =
Note: A single period, “.”, means “all rows” or “all columns”.
rows(matrix) / Returns the number of rows in matrix. / If x = , then
rows(x) = 2
cols(matrix) / Returns the number of columns in matrix. / If x = , then
cols(x) = 3
cdftc(test statistic, degrees of freedom) / Returns the area to the right of the test statistic for a t-distribution with the indicated degrees of freedom. / cdftc(1.6,10) returns the value 0.0703
cdftci(area to the right, degrees of freedom) / Returns the t-scorethat yields the indicated area on the right side of a t-distribution with the indicated degrees of freedom. / cdftci(0.025,100) returns the value 1.9840
cdfchic(test statistic, degrees of freedom) / Returns the area to the right of the test statistic for a χ2distribution with the indicated degrees of freedom. / cdfchic(2,3) returns the value 0.5724
cdffc(test statistic, degrees of freedom numerator, degrees of freedom denominator) / Returns the area to the right of the test statistic for anF distribution with the indicated degrees of freedom.
abs(matrix) / Converts each element of matrix to its absolute value. / If x = , then
abs(x) =
edit filename / Create a text file for executing Gauss code. / edit c:/users/default/desktop/prg.txt
Note: Gauss uses linux notation for directory paths. Use forward slash instead of back slash.
do until condition;
[program code]
endo; / Repeatedly executes a block of code until condition is met. The condition is tested when the program encounters the endo command. / j = 1;
do until j == 10;
print j;
j=j+1;
endo;
Note: When evaluating a variable, use double equal signs. When setting the value for a variable, use a single equal sign.
for variable (start, stop, step);
[program code]
endfor; / Repeatedly executes a block of code with variable starting at the value start, incrementing by step,and continuing until it reaches the value stop. / for j (1, 10, 1);
print j;
endfor;
Note: When evaluating a variable, use double equal signs. When setting the value for a variable, use a single equal sign.
if condition;
[program code]
endif; / Executes a block of code provided that condition is met. The condition is tested when the program encounters the endif command. / if j < 10;
j=abs(j);
endif;
label: / Marks a place in a program to which control can be sent. / goto RunRegression;
[program code]
RunRegression:
[program code]
goto label / Sends control to another point in a program. / goto RunRegression
gosub label
return / Sends control to another point in a program. Control returns where it left when the program encounters “return”. / gosub RunRegression;
[program code]
RunRegression:
[program code]
return;
lagn(matrix, index) / Lags matrix by index time periods. / xlagged = lagn(x,1)
packr(matrix) / Deletes the rows of a matrix that contain any missing values. / x = packr(x)
rndn(rows ,columns) / Generates a rows by columns matrix of standard normally distributed random numbers. / x = rndn(100,1)