\chapter{Introduction}
\label{intro}

\section{Why scripting?}

Hansl (the name expands, in recursive fashion, to ``Hansl's a neat
scripting language'') is gretl's scripting language. It's not something
new (although some of its features are new) and it's not an add-on or
anything of the sort, it's an integral part of gretl. What's new is
the name (we got tired of saying ``gretl's scripting language'') and
the fact that we decided it's time to produce a document that
specifically explains how to do gretl scripting to best effect.

Beginning users of gretl are likely to use the graphical user
interface (GUI, or point and click) at first, but all users should be
aware that many things are better done via scripting. So what exactly
is ``scripting'' and why is it (often, but not always) ``better''?

Basically, scripting is programming. But the two terms have somewhat
different connotations. ``Programming'' usually means using a
relatively low-level language such as C, C++ or Java, while
``scripting'' implies using a high-level language. In both cases
you're producing ``code''---that is, plain text stuff that somehow or
other causes the computer to do what you want---but ``low-level''
means that you're responsible for the details of what the computer
does, while with a high-level language you sail above such details,
and tell the computer what you want done in quite general (albeit
precise) terms. Scripting is much more easily learned than low-level
programming.

Why (or when) is scripting better than point-and-click? If you're
exploring a dataset, trying to get an initial impression of what data
it contains and how they might be related, then the GUI is the way to
go: you draw some graphs, look at some summary statistics, estimate
some models, run some diagnostic tests, examine the effects of adding
or dropping regressors, and so on. Gretl is designed to make this sort
of exploration easy, without any requirement that you learn the syntax
of a bunch of commands or functions. But if you know a dataset quite
well, and you want (say) to estimate a certain sequence of models and
test a number of specific hypotheses, the GUI is just an
encumbrance. You should think out in advance what you want to do,
write it up in the form of a script, then get gretl to execute the
script. 

Scripting offers two main advantages:

\begin{itemize}
\item Efficiency: You're carrying out a fairly complicated analysis,
  and after a while you decide that something is not quite right ---
  maybe the data should be in first differences or logs rather than
  levels. If your initial analysis is saved in script form, it's easy
  to modify a few lines and re-run it; with point-and-click you'd be
  laboriously redoing all the GUI interaction.
\item Replication: It's generally accepted that putative scientific
  results are real scientific results only if they can be replicated.
  If your econometric work is saved as a script your peers can run the
  script and (hopefully) get the same results. You too can replicate
  your own findings at a later date without having to wonder, now how
  did I get them, exactly? 
\end{itemize}

\section{Introducing hansl}

A hansl script is a plain text file containing a set of
\textsl{statements}, to be executed by gretl. These statements fall
into three broad classes: commands, function calls, and syntactical
``glue'' that enables you to make parts of a script conditional
(\texttt{if} \dots{} \texttt{endif}), to repeat sections of the script
(\texttt{loop} \dots{} \texttt{endloop}), to define your own
functions, and so on.

Like many econometrics packages, gretl offers both \textsl{commands}
and \textsl{functions}: what's the difference? Commands typically
carry out some sort of calculation and print some output. Functions
also typically carry out some sort of calculation, but unless they are
``command-like'' they generally don't print anything, instead they
\textsl{return} a value of some sort, which you can either print or
use as input to a further calculation. Another difference is that
commands generally have a more ``relaxed'' syntax and are hence easier
for beginners to use; working with functions generally demands greater
precision in what you type.

There's a second duality which gretl shares with many econometrics
programs, namely that between data \textsl{series} and
\textsl{matrices}. These are two of the numerical types available in
gretl, the third being \textsl{scalars}. Series are what you get when
you open a data file; they compose a \textsl{dataset}, along with
common information such as the time-series or panel structure of the
data. You generally work with series by name; in addition you can
construct named lists of series as a convenient shorthand. All the
series in a dataset are of the same length, though some may be padded
out with \texttt{NA}s (missing values). 




      
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "hansl-guide"
%%% End: 
