[Gretl-devel] Gretl's handling temporary variables

Allin Cottrell cottrell at wfu.edu
Tue Apr 1 09:19:13 EDT 2008


On Tue, 1 Apr 2008, Amir Reza Khosroshahi wrote:

> It seems that in gretl, you cannot have temporary variable? that are
> generated and then discarded in a command. For example the following
> commands are invalid in gretl:
> 
> > print $rsq
> 
> > smpl $t1+1 $t2
> 
> > print 2+2
> 
> But commands like these are perfectly logical in other 
> programming language, and being able to handle variables in this 
> way makes life much easier!

Gretl's "print" command is special, in that it's oriented towards 
printing data series, which can be referred to by ID number in the 
data set: thus "print 2" will print the second variable.  However, 
there are ways of getting the effect you want:

1) Use "eval".  I'm afraid this is not documented, I'll have to 
add that.  But you can do 

 eval $rsq
 eval 2+2

and so on: the result is computed, printed, and discarded.

2) Use "printf" (which is documented):

 printf "R-squared = %f\n", $rsq
 printf "%g\n", 2+2

As for the behavior with "smpl" -- yes, it would be nice to be 
able to use the sort of formulation you give.  We'll work on that.

Allin Cottrell





More information about the Gretl-devel mailing list