As you execute commands in gretl, using the GUI and filling in dialog entries, those commands are recorded in the form of a "script" or batch file. Such scripts can be edited and re-run, using either gretl or the command-line client, gretlcli.
To view the current state of the script at any point in a gretl session, choose "View command log" under the File menu. This log file is called session.inp and it is overwritten whenever you start a new session. To preserve it, save the script under a different name. Script files will be found most easily, using the GUI file selector, if you name them with the extension ".inp".
To open a script you have written independently, use the "File, Open command file" menu item; to create a script from scratch use the "File, New command file" item or the "new script" toolbar button. In either case a script window will open (see Figure 3-1).
The toolbar at the top of the script window offers the following functions (left to right): (1) Save the file; (2) Save the file under a specified name; (3) Print the file (under Windows or the gnome desktop only); (4) Execute the commands in the file; (5) Copy selected text; (6) Paste the selected text; (7) Find and replace text; (8) Undo the last Paste or Replace action; (9) Help (if you place the cursor in a command word and press the question mark you will get help on that command); (10) Close the window.
When you click the Execute icon or choose the "File, Run" menu item all output is directed to a single window, where it can be edited, saved or copied to the clipboard.
To learn more about the possibilities of scripting, take a look at the gretl Help item "Script commands syntax," or start up the command-line program gretlcli and consult its help, or consult Chapter 10 in this manual. In addition, the gretl package includes over 70 "practice" scripts. Most of these relate to Ramanathan (2002), but they may also be used as a free-standing introduction to scripting in gretl and to various points of econometric theory. You can explore the practice files under "File, Open command file, practice file" There you will find a listing of the files along with a brief description of the points they illustrate and the data they employ. Open any file and run it to see the output.
Note that long commands in a script can be broken over two or more lines, using backslash as a continuation character.
You can, if you wish, use the GUI controls and the scripting approach in tandem, exploiting each method where it offers greater convenience. Here are two suggestions.
Open a data file in the GUI. Explore the data — generate graphs, run regressions, perform tests. Then open the Command log, edit out any redundant commands, and save it under a specific name. Run the script to generate a single file containing a concise record of your work.
Start by establishing a new script file. Type in any commands that may be required to set up transformations of the data (see the genr command in Chapter 10 below). Typically this sort of thing can be accomplished more efficiently via commands assembled with forethought rather than point-and-click. Then save and run the script: the GUI data window will be updated accordingly. Now you can carry out further exploration of the data via the GUI. To revisit the data at a later point, open and rerun the "preparatory" script first.
When you estimate a model using point-and-click, the model results are displayed in a separate window, offering menus which let you perform tests, draw graphs, save data from the model, and so on. Ordinarily, when you estimate a model using a script you just get a non-interactive printout of the results. You can, however, arrange for models estimated in a script to be "captured", so that you can examine them interactively when the script is finished. Here is an example of the syntax for achieving this effect:
Model1 <- ols Ct 0 Yt
That is, you type a name for the model to be saved under, then a back-pointing "assignment arrow", then the model command. You may use names that have embedded spaces if you like, but such names must always be wrapped in double quotes:
"Model 1" <- ols Ct 0 Yt
Models saved in this way will appear as icons in the gretl session window (see the Section called The "session" concept) after the script is executed. In addition, you can arrange to have a named model displayed (in its own window) automatically as follows:
Model1.show
Again, if the name contains spaces it must be quoted:
"Model 1".show
The same commands can be used for graphs. For example the following will create a plot of Ct against Yt, save it under the name "CrossPlot", and have it displayed:
CrossPlot <- gnuplot Ct Yt CrossPlot.show