Skip to content

Input‐Output information

atecon edited this page Jan 20, 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

Store a dataset

The store command allows you to store a dataset or matrices in various formats. The following example shows on how to store a list of as a csv file:

nulldata 3
series y = normal()
series x = y + 1.6*normal()
series z = normal()

list Store = y x
store "PATH+FILENAME.csv" Store  # drop `Store` if you want to store all series

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 for which we added column labels before:

matrix m = mnormal(5, 3)
cnameset(m, defarray("A", "B", "C"))  # attach column labels
print m

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   # the preserve option keeps previously defined variables alive
print dataset -o

The output is:

             A            B            C

1    -1.290321     0.093702     0.162854
2    -0.706230    -0.136629     0.705183
3     0.100014    -0.544113    -0.596228
4    -1.324291    -1.026685     2.003978
5     0.591764    -0.779717    -0.463718

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

Print and store model summary

Model equation

The eqnprint command must follow the estimation of a model, and prints the estimated model in the form of a LaTeX equation:

open abdata.gdt --quiet
ols ys const n w --quiet
tabprint --output="./output/regression_equation.tex"

Tabular form

The tabprint command must follow the estimation of a model. Prints the model in tabular form. The format is governed by the extension of the specified filename: .tex for LaTeX, .rtf for RTF (Microsoft's Rich Text Format), or .csv for comma-separated.

open abdata.gdt --quiet --preserve
ols ys const n w --simple
tabprint --output="./output/regression_output.rtf"

Multiple models

By means of a so called model table, one can summarize estimation results of different specifications. However, the dependent variable must be the same for all models. See the help on the [modeltab](https://gretl.sourceforge.net/gretl-help/cmdref.html#modeltab) command for details. An example adding three specifications to the table follows. The modelstab show command prints the output on the screen but which can be stored, too:

open abdata.gdt --quiet --preserve

m1 <- ols ys const --quiet
modeltab add

m2 <- ols ys const n --quiet
modeltab add

m3 <- ols ys const n w --quiet
modeltab add

modeltab show
modeltab --output="./output/regression_table.rtf"
modeltab free

The model table looks like:

Pooled OLS estimates
Dependent variable: ys

                 (1)          (2)          (3)     

const            4.638***     4.631***     4.604***
             (0.002926)   (0.003712)    (0.03510)

n                          0.006245***  0.006269***
                          (0.002175)   (0.002175)

w                                       0.008756   
                                        (0.01110)

        n         1031         1031         1031
Adj. R**2       0.0000       0.0070       0.0066
      lnL        975.8        979.9        980.2

Standard errors in parentheses
*   significant at the 10 percent level
**  significant at the 5 percent level
*** significant at the 1 percent level