Write a scalar to a FAME database

For questions and discussion related to reading in and working with data.

Write a scalar to a FAME database

Postby writ » Wed Feb 16, 2011 9:00 am

Hello all,

I cannot seem to figure out how to write a scalar to a FAME database. The COPY instruction appears to only work for data series.

More generally, what is the best way to output model statistics from a program in a way that could later be recalled by an external program (Rats or otherwise)? For example, if I have two programs (file1.prg and file2.prg) that each run separate OLS regressions, is there a way to store the file1_Rbarsq and file2_Rbarsq that would then be accessible by their variable names from a third program (file3.prg)?

The best I seem to be able to do is something like the following:

Code: Select all
open data quahvahey.rat
calendar(m) 1968:1
data(format=rats) 1968:1 1993:5 indprod lrpi

set y = indprod
set x = lrpi

linreg y
# constant x x{1}

compute model1_Rbar = %RBARSQ

open(format=rats) copy stats.rat
write(unit=copy) model1_Rbar


---- new program ----

Code: Select all
decl real m1

open data stats.rat
read(unit=data) m1

disp m1


I can make this method work although it is far from ideal as it will become very cumbersome as the number of models and statistics that I store increases.

Also, can anyone give me a bit of insight into the I/O format "rats"? Is there documentation that I can read as to how it differs from a regular ASCII file?

Thanks in advance,

Geoff
writ
 
Posts: 6
Joined: Wed Jan 26, 2011 9:09 am

Re: Write a scalar to a FAME database

Postby TomDoan » Wed Feb 16, 2011 4:56 pm

RATS doesn't read or write anything but data series from/to a FAME database. Similarly, RATS format is for data series only. Formats that can take strings and scalars are text (free format or FORTRAN format), Excel and WKS (and binary, but that's not recommended). Is there a reason you want to use FAME rather than one of the more basic formats.
TomDoan
 
Posts: 3403
Joined: Wed Nov 01, 2006 5:36 pm

Re: Write a scalar to a FAME database

Postby writ » Thu Feb 17, 2011 10:22 am

Hi Tom,

My exercise is to run a horse race between a number of competing forecasting models that use different datasets and training periods in order to declare a "winner" based on a few basic criteria. Once the winner is selected, my final forecast will be based on the forecast from that model. It's a bit more complicated than that but that is the gist of it.

Let's say I have 3 models and I calculate the following statistics from those three models: model1_MSE, model1_MAE, model1_theil. If I write those to a text file, say:

Code: Select all
model1_MSE::0.8
model1_MAE::0.5
model1_theil::0.3

model2_MSE::0.7
model2_MAE::0.4
model2_theil::0.4

etc.


Retrieving these statistics from the text file is feasible but cumbersome. Alternatively, if these were stored in a FAME database as scalars, I could simply extract them based on their variable name.

Thanks for any insight,

Geoff
writ
 
Posts: 6
Joined: Wed Jan 26, 2011 9:09 am

Re: Write a scalar to a FAME database

Postby TomDoan » Thu Feb 17, 2011 6:50 pm

RATS isn't Perl, but if you have a file (which I call bocresults.txt) with lines like:

model1_MSE::0.8
model1_MAE::0.5
model1_theil::0.3
model2_MSE::0.7
model2_MAE::0.4
model2_theil::0.4

then the following will allow you to fetch the statistics by name.

Code: Select all
open data bocresults.txt
dec vect[string] bocresults
read(varying) bocresults
*
function findstat modelname statname
type real findstat
type string modelname statname
*
local integer len ok
local string  test
*
compute test=modelname+"_"+statname
compute len =%strlen(test)
do i=1,%rows(bocresults)
   if %strcmpnc(%left(bocresults(i),len),test)==0 {
      compute findstat=%value(%mid(bocresults(i),len+3,-1))
      return
   }
end loop
compute findstat=%na
end


For instance, findstat("model1","theil") will be .3
TomDoan
 
Posts: 3403
Joined: Wed Nov 01, 2006 5:36 pm

Re: Write a scalar to a FAME database

Postby writ » Tue Feb 22, 2011 11:14 am

"RATS is not Perl" -- you can say that again. Thanks for this code -- that is a very useful helper function.

Another option would be to store the scalars as "fake" series in FAME.

A third option is to use Perl to take my data to presentation.

Thanks again Tom.
writ
 
Posts: 6
Joined: Wed Jan 26, 2011 9:09 am


Return to Data: Reading, Writing, Transforming

Who is online

Users browsing this forum: No registered users and 2 guests