[Gretl-users] new string handling (was Re: Unit Root Test)

Allin Cottrell cottrell at wfu.edu
Sun Feb 3 21:15:41 EST 2008


On Sun, 3 Feb 2008, I wrote:

> In the meantime this might be helpful: if you estimate an 
> ar(i)ma model using the --x-12-arima option in gretl, a plain 
> text file named varname.rts (where "varname" is the name of the 
> dependent variable) is written.

Around Christmas I added some functionality for handling strings.  
I think the timing was bad and it wasn't much noticed, and as a 
result was not much debugged.  However, reading roots information 
from a X-12-ARIMA .rts file is a handy case in point.  I've had a 
go at this, and in the process have fixed a few bugs and added 
some more functionality.  Find below a function that reads an .rts 
file and returns a roots matrix.  The new string-handling idioms 
are explained in (a) "help sscanf" and (b) section 11.2 of the 
User's Guide (CVS and Windows snapshot).

<script>
function read_x12a_roots (series y, int type[1:2:1])

  # compose the name of the X12A roots file...
  sprintf yfile, "%s/%s.rts", @x12adir, argname(y) 
  # and grab its content into a string
  string rts = readfile(@yfile)

  matrix r
  matrix R

  if (type = 1)
     string targ = "AR"
  else
     string targ = "MA"
  endif

  string line = strstr(@rts, @targ)
  loop while isstring(line) --quiet
     # offset on line to find the numbers
     string line = @line + 18
     # get 4 values: real, imaginary, modulus, frequency
     sscanf @line, "%m",  r
     R = R|r
     string line = strstr(@line, @targ)
  endloop

  return matrix R
end function 

open data9-7
arma 2 1 ; QNC --x-12-arima
AR_roots = read_x12a_roots(QNC, 1)
MA_roots = read_x12a_roots(QNC, 2)
print AR_roots MA_roots
</script>

Allin.


More information about the Gretl-users mailing list