Skip to content

Input‐Output information

atecon edited this page Jan 19, 2024 · 3 revisions

Open a dataset

By means of the open command, Gretl can open various file types as a dataset

Here is a simple example for opening a csv-dataset. First, a string is defined which is substituted via the @ symbol:

string filename = "PATH + FILENAME.csv"
open "@filename

Open and store matrices

Store as mat-file

Might be useful for storing numeric output in matrix form. See the mwrite command for details.

Store as csv-file

You can easily store a matrix as a csv file. The advantage is that you can read-in that format easily into Excel or Gretl again. Here is an example on how store a matrix:

matrix m = mnormal(3, 2)
string filename = "PATH+FILENAME.csv"
store "@filename" --matrix=m

This stored matrix in csv format can be opened as a dataset again:

string filename = "PATH+FILENAME.csv"
open "@filename" --preserve

Store textual printout

Outfile

Assume you print some string, matrix or some other Gretl object. You store the textual printout as a txt-file by means of the outfile command. The example prints the values of a matrix to the txt-file:

matrix m = mnormal(3, 2)

string filename = "PATH+FILENAME.txt"
outfile "@filename
    printf "%12.2f\n", m
end outfile
Clone this wiki locally