Error G0125 : Read past end of file

Hello,

I am trying to run the bdpapmom.g -- the program from "Priors from General Equilibrium Models for VARs" wrriten by  Del Negro and  Schorfheide (2004).

But the error output is C:\gauss_10\procs\dpapmom.g(39):error G0125: Read past end of file.

Can you tell me why?

The bdpapmom.g is: 


/* filename: bdpapmom.g
** description: Metropolis Hastings Batch
** created: 11/05/01
*/

new;
closeall;
library pgraph, user;
cls;

#include C:\gauss_10\pathspec.g
#include C:\gauss_10\varspec.g

mhrun = "1";

nburn = 1; /* Number of initial draws to be discarded */
hpdprob = 0.90 ;
nblock = 500;

outstr = outpath $+ "\\dpapmom" $+ mhrun $+ ".out";

output file = ^outstr reset;
output file = ^outstr off;
Tind = 1;
do until Tind > rows(Tgrid);

   T0 = Tgrid[Tind,1];
   Tend = Tgrid[Tind,2];

   lamind = 1;
   do until lamind > rows(lamgrid);

      locate 1,1;
      "Sample Iteration" Tind "of" rows(Tgrid);
      "Lambda Iteration" Lamind "of" rows(lamgrid);

      lambda = lamgrid[lamind];
      gosub runproc;

      lamind = lamind+1;

   endo;

   Tind = Tind+1;

endo;

end;

runproc:

screen off;
output file = ^outstr on;
"";
"";
"";
"=========================================================";
"Index L,T" lamind Tind;
"LAMBDA = " lambda;
"T0 = " T0;
"TEND = " TEND;
"MSPEC = " mspec;
"MHRUN = " $mhrun;
"---------------------------------------------------------";
output file = ^outstr off;
screen on;

#include C:\gauss_10\procs\dpapmom.g

return;

 

 

 

The dpapmom.g is:


/* filename: dpapmom.g
** description: The program computes posterior mean and confidence bands
** for the DSGE parameters
** created: 11/06/01
*/

/********************************************************
** Open files with parameter draws
*/

modelid = ftos(mspec,"%*.*lf",1,0);

if lamind < 10;
   llam = "0" $+ ftos(lamind,"%*.*lf",1,0);
else;
   llam = ftos(lamind,"%*.*lf",2,0);
endif;

if Tind < 10;
   lsamp = "0" $+ ftos(Tind,"%*.*lf",1,0);
else;
   lsamp = ftos(Tind,"%*.*lf",2,0);
endif;

lpath = parapath $+ "\\mhrun" $+ mhrun $+ "\\";
opath = parapath $+ "\\mhrun" $+ mhrun $+ "\\";
if lamind == 0;
   ldraw = lpath $+ modelid $+ "01" $+ lsamp $+ "mh";
   odraws = lpath $+ modelid $+ "01" $+ lsamp $+ "mhs";
else;
   ldraw = lpath $+ modelid $+ llam $+ lsamp $+ "mh";
   odraws = opath $+ modelid $+ llam $+ lsamp $+ "mhs";
endif;

open fhdraw = ^ldraw for read;

drawrow = readr( fhdraw, nburn);
drawdim = cols(drawrow);
drawrow = seekr( fhdraw, nburn);

/* Part 1: Compute the mean of x(i) and x^2(i)
*/
drawmean = zeros(1,drawdim);
drawsqmean = zeros(1,drawdim);
drawcross = zeros(drawdim,drawdim);

eofloop = 0;
ndraws = 0;

do until eofloop;

   drawblock = readr( fhdraw, nblock );

   drawmean = drawmean + sumc(drawblock)';
   drawsqmean = drawsqmean + sumc(drawblock^2)'; 
   drawcross = drawcross + drawblock'*drawblock;

   ndraws = ndraws + rows(drawblock);

   eofloop = eof(fhdraw);

endo;

drawmean = drawmean/ndraws;
drawsqmean = drawsqmean/ndraws;
drawstdd = sqrt(drawsqmean - (drawmean)^2);
drawcov = drawcross/ndraws - drawmean'*drawmean;

/* Part 2: HPD Interval
*/
drawrow = seekr( fhdraw, nburn);
drawci = zeros(2,drawdim);

j = 1;
do until j > drawdim;

   /* Read only the j'th column
   */
   drawrow = seekr( fhdraw, nburn);
   drawblock = readr( fhdraw, 1);

   drawcol = drawblock[1,j];
   eofloop = 0;
   ndraws = 1;

   do until eofloop;

      drawblock = readr( fhdraw, nblock );
      drawcol = drawcol | drawblock[.,j];
      ndraws = ndraws + rows(drawblock);
      eofloop = eof(fhdraw);

   endo;

   drawci[.,j] = hpdint(drawcol,hpdprob);
   j = j+1;

endo;
clear drawcol;

/* Report Posterior Mean and stderror
**
*/
screen off;
output file = ^outstr on;

load path = ^priopath para_names;
"Parameter | Mean | StdD | CI(LOW) | CI(HIGH)";
outmat = para_names'~ drawmean' ~ drawstdd' ~ drawci' ;
let mask[1,5] = 0 1 1 1 1;
let fmt[5,3] =
"-*.*s " 8 4
"*.*lf " 8 4
"*.*lf " 8 4
"*.*lf " 8 4
"*.*lf " 8 4;

d = printfm(outmat,mask,fmt);

output file = ^outstr off;
screen on;

create fhdraws = ^odraws with DRAWSUM, drawdim, 8;
wr=writer(fhdraws, real(drawmean | drawstdd | drawcov | drawci) );
closeall fhdraws;
/**************************************************************/
/* Procedures */
/**************************************************************/

proc(1) = hpdint(draws,percent);
local ndraws, drawdim, hpdband, nwidth, i, drawcoli,
bup, minwidth, newwidth, j;

   drawdim = cols(draws);
   ndraws = rows(draws);
   hpdband = zeros(2,drawdim);
   nwidth = int(percent*ndraws);

   i = 1;
   do until i > drawdim;
      drawcoli = draws[.,i];
      /* sort response for period i, element 1 is max
      */
      drawcoli = rev(sortc(drawcoli,1));
      bup = 1;
      minwidth = drawcoli[1] - drawcoli[nwidth];
      j = 2;
      do until j > (ndraws-nwidth+1);
         newwidth = drawcoli[j] - drawcoli[j+nwidth-1];
         if newwidth < minwidth;
            bup = j;
            minwidth = newwidth;
         endif;
         j = j+1;
      endo;
      hpdband[2,i] = drawcoli[bup];
      hpdband[1,i] = drawcoli[bup+nwidth-1];
      i = i+1;
   endo;
   retp(hpdband);
endp;

1 Answer



0



Based upon the code that you sent and the error message, I would assume that the error message comes from the 'readr' line in the code snippet below:

open fhdraw = ^ldraw for read;

drawrow = readr( fhdraw, nburn);
drawdim = cols(drawrow);
drawrow = seekr( fhdraw, nburn);

What is this code trying to do?
The first line of code:

//fhdraw is a file handle
//ldraw is a string containing the name of the dataset file
open fhdraw = ^ldraw for read;

is trying to open a dataset and return a file handle to that file. The name of the file is whatever the string variable, ldraw, has been assigned to. The caret operator (^), tells GAUSS not to open a file named ldraw.dat, but that ldraw is a string variable, containing the name of the dataset. For example, if we had a dataset named myproject.dat, then we could get a file handle to that file like this:

//Create string variable with filename
fname = "myproject.dat";

//Open 'myproject.dat' and return a file handle
open fhdraw = ^fname for read;

The second line of code:

drawrow = readr( fhdraw, nburn);

is trying to read in nburn rows of the dataset. However, if the dataset contains fewer rows than nburn, the program will terminate with the error G0125 : Read past end of file. This is most likely what is happening.
How do we find out if this is actually the problem?
We can add a couple of simple diagnostic lines of code that will tell us if we are correct. We need to change the original four lines of code from the top of this message, to instead:

print "attempting to open dataset file :";
print ldraw;

open fhdraw = ^ldraw for read;
if fhdraw == -1;
   print "File "$+ldraw$+" could not be opened";
   end;
endif;

ldraw_rows = rowsf(fhdraw);
print "Dataset file "$+ldraw$+" contains " ldraw_rows " rows";
print "About to attempt to read " nburn " rows";

drawrow = readr( fhdraw, nburn);
drawdim = cols(drawrow);
drawrow = seekr( fhdraw, nburn);

Now if we confirm that this is the problem, we can look at finding why the file does not contain as many rows as we expect.

aptech

1,773

Your Answer

1 Answer

0

Based upon the code that you sent and the error message, I would assume that the error message comes from the 'readr' line in the code snippet below:

open fhdraw = ^ldraw for read;

drawrow = readr( fhdraw, nburn);
drawdim = cols(drawrow);
drawrow = seekr( fhdraw, nburn);

What is this code trying to do?
The first line of code:

//fhdraw is a file handle
//ldraw is a string containing the name of the dataset file
open fhdraw = ^ldraw for read;

is trying to open a dataset and return a file handle to that file. The name of the file is whatever the string variable, ldraw, has been assigned to. The caret operator (^), tells GAUSS not to open a file named ldraw.dat, but that ldraw is a string variable, containing the name of the dataset. For example, if we had a dataset named myproject.dat, then we could get a file handle to that file like this:

//Create string variable with filename
fname = "myproject.dat";

//Open 'myproject.dat' and return a file handle
open fhdraw = ^fname for read;

The second line of code:

drawrow = readr( fhdraw, nburn);

is trying to read in nburn rows of the dataset. However, if the dataset contains fewer rows than nburn, the program will terminate with the error G0125 : Read past end of file. This is most likely what is happening.
How do we find out if this is actually the problem?
We can add a couple of simple diagnostic lines of code that will tell us if we are correct. We need to change the original four lines of code from the top of this message, to instead:

print "attempting to open dataset file :";
print ldraw;

open fhdraw = ^ldraw for read;
if fhdraw == -1;
   print "File "$+ldraw$+" could not be opened";
   end;
endif;

ldraw_rows = rowsf(fhdraw);
print "Dataset file "$+ldraw$+" contains " ldraw_rows " rows";
print "About to attempt to read " nburn " rows";

drawrow = readr( fhdraw, nburn);
drawdim = cols(drawrow);
drawrow = seekr( fhdraw, nburn);

Now if we confirm that this is the problem, we can look at finding why the file does not contain as many rows as we expect.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy