"do while" command problems

Hey guys,

I am a very beginner with gauss but have to use it for my master thesis in order to run a program which is not mine. The Program is about some time-series analysis of a [271,10] raw data. I updated this raw data in time to present thus it becomes a [278,10] raw data. The problem is that in the output data the last 7 rows are empty for all columns except for the first (GDP). I think it has something to do with the following part of the code:

i = 1;
do while i <= lastrow-52;
beta = invpd(xr[i:i+39,.]'xr[i:i+39,.])*xr[i:i+39,.]'yr[i:i+39]; //reg yr on xr
x[48+i,4] = xr[i+43,.]*beta; //for 1960.1 onward
i = i+1;
endo;

I do not understand this.

I would be deeply grateful if someone could help me on this. For further information please contact me. I am behind the eight ball...

4 Answers



0



//Run the loop through: i = 1, 2, 3...lastrow-52
i = 1;
do while i <= lastrow-52;
   //Ordinary Least Squares estimation of a sliding window of 40 observations
   //i.e. 1:40, 2:41, 3:42, etc 
   beta = invpd(xr[i:i+39,.]'xr[i:i+39,.])*xr[i:i+39,.]'yr[i:i+39]; //reg yr on xr
   //Predict y_hat and store it in the 4th column of 'x'
   x[48+i,4] = xr[i+43,.]*beta; //for 1960.1 onward
   //Increase 'i' for next iteration of the loop
   i = i+1;
endo;

Noting in that seems to be dependent on the number of observations of the input data, unless lastrow is not set correctly. You should check the value of lastrow.

However, I would guess that the problem is with the loading of your data. I would guess that the program starts with something like this at the top:

load mydata[278,10] = mydata.txt

Assuming that is how the program starts, add these lines after it (substitute the name of your actual file and variable names):

load mydata[278,10] = mydata.txt

print "My data after loading = ";
print mydata;
//stop program so we can look at printed output of data
end;

That will help you to confirm that your data is being read correctly.

aptech

1,773


0



Thanks for your response.

The following is my header:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[278,10] = nr2_1214.q;
screen off;
format /rd 9,4;
lastrow = rows(dat);
daq1 = zeros(lastrow,8);
daq2 = zeros(lastrow,4);

 

But if I try what you suggested:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[278,10] = nr2_1214.q;
print "My data after loading = ";
print nr2_1214;

end;

I get this:

G0025 : Undefined symbol: 'nr2_1214' [rst_data_b.g, line 17]
What am I doing wrong?
Again thanks for your support!


0



You need to print the GAUSS matrix that the data was loaded into. The statement:

load dat[278,10] = nr2_1214.q;

Reads data from the file nr2_1214.q and creates a 278x10 matrix named dat. You need to print dat. Like this:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[278,10] = nr2_1214.q;
print "My data after loading = ";
print dat;

end;

aptech

1,773


0



Oh okay, well, I think here is the Problem:

The printed data goes to row 271 as the initial code from the authors (to the year 2014Q3), after that in row 272 (where I started to update to 2016Q3) the data set starts from the beginning with the year 1947Q1...

Do you have an idea where this comes from?

For better understanding the context, here is the full code:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[279,10] = nr2_1214.q;

screen off;
format /rd 9,4;
lastrow = rows(dat);
daq1 = zeros(lastrow,8);
daq2 = zeros(lastrow,4);

// 1947.1 - 2013.4
// Column 1: DATE (1947.1-2013.4)
// Column 2: XGDP (1947.1-present)
// Column 3: PCNIA (1948.2-present)
// Column 4: PCXFE (1959.1-present)
// Column 5: IMPPETROL (1967.1-present)
// Column 6: POIL (1948.4-present)
// Column 7: IMPXCOMP (1967.1-present)
// Column 8: PMO (1956.1-present)
// Column 9: RFFE (1954.1-present)
// Column 10: NYFRB (1950.1-2002.2)

daq1[.,1] = dat[.,1];
daq1[.,2] = dat[.,2];
daq1[.,3] = zeros(lastrow,1);
daq1[.,4] = dat[.,3];
daq1[.,5] = dat[.,4];
daq1[.,6] = dat[.,6];
daq1[.,7] = dat[.,8];
daq1[.,8] = dat[.,9];

// 1947.1 - 2008.4
// Column 1: DATE in YYYYQ format
// Column 2: XGDP (1947.1-present)
// Column 3: Blank (removed LHP)
// Column 4: PCNIA (1948.2-present)
// Column 5: PCXFE (1959.1-present)
// Column 6: POIL (1948.4-present)
// Column 7: PMO (1956.1-present)
// Column 8: RFFE (1954.1-present)

daq2[.,1] = dat[.,2];
daq2[.,2] = dat[.,10];
daq2[.,3] = dat[.,7];
daq2[.,4] = dat[.,5];
// 1947.1 - 2008.4
// Column 1: DATE in YYYYQ format
// Column 2: NYFRB (1950.1-2002.2)
// Column 3: IMPXCOMP (1967.1-present)
// Column 4: IMPPETROL (1967.1-present)

// natural log XGDP and LHP
daq1[.,2] = ln(daq1[.,2]);

// PMO spliced with IMPXCOMP at 1967.1
daq2[1:80,3] = daq1[1:80,7]*daq2[81,3]/daq1[81,7];

// POIL spliced with IMPPETROL at 1967.1
daq2[1:80,4] = daq1[1:80,6]*daq2[81,4]/daq1[81,6];

// annualized quarterly PCNIA, PCXFE, POIL, PMO inflation
daq1[2:lastrow,4:7] = 400*ln(daq1[2:lastrow,4:7]./daq1[1:lastrow-1,4:7]);

// annualized quarterly IMPXCOMP inflation
daq2[2:lastrow,3] = 400*ln(daq2[2:lastrow,3]./daq2[1:lastrow-1,3]);

// annualized quarterly POIL spliced with IMPPETROL inflation
daq2[2:lastrow,4] = 400*ln(daq2[2:lastrow,4]./daq2[1:lastrow-1,4]);

// FRBNY discount rate converted to effective annual yield
daq2[.,2] = 100*((1+daq2[.,2]/36000)^365-1);

// 1948.1 - 2008.4
// NOTE: Make sure the start and end periods are set correctly
daq = daq1[5:lastrow,.]~daq2[5:lastrow,2:4];

// create a matrix full of missing values
mv = miss(0,0);
x = reshape(mv,lastrow-4,7);

x[.,1:2] = daq[.,2:3]; //GDP and LHP
x[.,3] = daq[1:45,4]|daq[46:lastrow-4,5]; // PCNIA spliced with PCXFE at 1959.3
x[.,5] = daq[.,11]; // POIL spliced with IMPPETROL at 1967.1
x[.,6] = daq[.,10]; // PMO spliced with IMPXCOMP at 1967.1
x[.,7] = daq[1:68,9]|daq[69:lastrow-4,8]; // NYFRB spliced with FFR at 1965.1

// inflation expectations as described in the paper appendix
yr = (x[10:lastrow-4,3]+x[9:lastrow-5,3]+x[8:lastrow-6,3]+x[7:lastrow-7,3])/4;
xr = x[6:lastrow-4,3]~x[5:lastrow-5,3]~x[4:lastrow-6,3]~ones(lastrow-9,1);

i = 1;
do while i <= lastrow-52;
beta = invpd(xr[i:i+39,.]'xr[i:i+39,.])*xr[i:i+39,.]'yr[i:i+39]; //reg yr on xr
x[48+i,4] = xr[i+43,.]*beta; //for 1960.1 onward
i = i+1;
endo;

// 1948.1 - current
// Column 1: XGDP (1948.1-present)
// Column 2: PCNIA spliced with PCXFE (1948.3-present)
// Column 3: Inflation expectations (1960.1-present)
// Column 4: POIL spliced with IMPPETROL (1949.1-present)
// Column 5: PMO spliced with IMPXCOMP (1956.2-present)
// Column 6: NYFRB spliced with RFFE (1948.1-present)
y = x[.,1]~x[.,3:7];
y;

output off;
screen on;

end;

 

Thank you very much!!!

Your Answer

4 Answers

0
//Run the loop through: i = 1, 2, 3...lastrow-52
i = 1;
do while i <= lastrow-52;
   //Ordinary Least Squares estimation of a sliding window of 40 observations
   //i.e. 1:40, 2:41, 3:42, etc 
   beta = invpd(xr[i:i+39,.]'xr[i:i+39,.])*xr[i:i+39,.]'yr[i:i+39]; //reg yr on xr
   //Predict y_hat and store it in the 4th column of 'x'
   x[48+i,4] = xr[i+43,.]*beta; //for 1960.1 onward
   //Increase 'i' for next iteration of the loop
   i = i+1;
endo;

Noting in that seems to be dependent on the number of observations of the input data, unless lastrow is not set correctly. You should check the value of lastrow.

However, I would guess that the problem is with the loading of your data. I would guess that the program starts with something like this at the top:

load mydata[278,10] = mydata.txt

Assuming that is how the program starts, add these lines after it (substitute the name of your actual file and variable names):

load mydata[278,10] = mydata.txt

print "My data after loading = ";
print mydata;
//stop program so we can look at printed output of data
end;

That will help you to confirm that your data is being read correctly.

0

Thanks for your response.

The following is my header:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[278,10] = nr2_1214.q;
screen off;
format /rd 9,4;
lastrow = rows(dat);
daq1 = zeros(lastrow,8);
daq2 = zeros(lastrow,4);

 

But if I try what you suggested:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[278,10] = nr2_1214.q;
print "My data after loading = ";
print nr2_1214;

end;

I get this:

G0025 : Undefined symbol: 'nr2_1214' [rst_data_b.g, line 17]
What am I doing wrong?
Again thanks for your support!
0

You need to print the GAUSS matrix that the data was loaded into. The statement:

load dat[278,10] = nr2_1214.q;

Reads data from the file nr2_1214.q and creates a 278x10 matrix named dat. You need to print dat. Like this:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[278,10] = nr2_1214.q;
print "My data after loading = ";
print dat;

end;
0

Oh okay, well, I think here is the Problem:

The printed data goes to row 271 as the initial code from the authors (to the year 2014Q3), after that in row 272 (where I started to update to 2016Q3) the data set starts from the beginning with the year 1947Q1...

Do you have an idea where this comes from?

For better understanding the context, here is the full code:

cls;

dir = "/Users/Maximilian/gauss16/lw_rstar_1214";
dateapp = datestrymd(0);
filename = dir$+dateapp$+"_XCOMP.DAT";

output file = ^filename reset;

load dat[279,10] = nr2_1214.q;

screen off;
format /rd 9,4;
lastrow = rows(dat);
daq1 = zeros(lastrow,8);
daq2 = zeros(lastrow,4);

// 1947.1 - 2013.4
// Column 1: DATE (1947.1-2013.4)
// Column 2: XGDP (1947.1-present)
// Column 3: PCNIA (1948.2-present)
// Column 4: PCXFE (1959.1-present)
// Column 5: IMPPETROL (1967.1-present)
// Column 6: POIL (1948.4-present)
// Column 7: IMPXCOMP (1967.1-present)
// Column 8: PMO (1956.1-present)
// Column 9: RFFE (1954.1-present)
// Column 10: NYFRB (1950.1-2002.2)

daq1[.,1] = dat[.,1];
daq1[.,2] = dat[.,2];
daq1[.,3] = zeros(lastrow,1);
daq1[.,4] = dat[.,3];
daq1[.,5] = dat[.,4];
daq1[.,6] = dat[.,6];
daq1[.,7] = dat[.,8];
daq1[.,8] = dat[.,9];

// 1947.1 - 2008.4
// Column 1: DATE in YYYYQ format
// Column 2: XGDP (1947.1-present)
// Column 3: Blank (removed LHP)
// Column 4: PCNIA (1948.2-present)
// Column 5: PCXFE (1959.1-present)
// Column 6: POIL (1948.4-present)
// Column 7: PMO (1956.1-present)
// Column 8: RFFE (1954.1-present)

daq2[.,1] = dat[.,2];
daq2[.,2] = dat[.,10];
daq2[.,3] = dat[.,7];
daq2[.,4] = dat[.,5];
// 1947.1 - 2008.4
// Column 1: DATE in YYYYQ format
// Column 2: NYFRB (1950.1-2002.2)
// Column 3: IMPXCOMP (1967.1-present)
// Column 4: IMPPETROL (1967.1-present)

// natural log XGDP and LHP
daq1[.,2] = ln(daq1[.,2]);

// PMO spliced with IMPXCOMP at 1967.1
daq2[1:80,3] = daq1[1:80,7]*daq2[81,3]/daq1[81,7];

// POIL spliced with IMPPETROL at 1967.1
daq2[1:80,4] = daq1[1:80,6]*daq2[81,4]/daq1[81,6];

// annualized quarterly PCNIA, PCXFE, POIL, PMO inflation
daq1[2:lastrow,4:7] = 400*ln(daq1[2:lastrow,4:7]./daq1[1:lastrow-1,4:7]);

// annualized quarterly IMPXCOMP inflation
daq2[2:lastrow,3] = 400*ln(daq2[2:lastrow,3]./daq2[1:lastrow-1,3]);

// annualized quarterly POIL spliced with IMPPETROL inflation
daq2[2:lastrow,4] = 400*ln(daq2[2:lastrow,4]./daq2[1:lastrow-1,4]);

// FRBNY discount rate converted to effective annual yield
daq2[.,2] = 100*((1+daq2[.,2]/36000)^365-1);

// 1948.1 - 2008.4
// NOTE: Make sure the start and end periods are set correctly
daq = daq1[5:lastrow,.]~daq2[5:lastrow,2:4];

// create a matrix full of missing values
mv = miss(0,0);
x = reshape(mv,lastrow-4,7);

x[.,1:2] = daq[.,2:3]; //GDP and LHP
x[.,3] = daq[1:45,4]|daq[46:lastrow-4,5]; // PCNIA spliced with PCXFE at 1959.3
x[.,5] = daq[.,11]; // POIL spliced with IMPPETROL at 1967.1
x[.,6] = daq[.,10]; // PMO spliced with IMPXCOMP at 1967.1
x[.,7] = daq[1:68,9]|daq[69:lastrow-4,8]; // NYFRB spliced with FFR at 1965.1

// inflation expectations as described in the paper appendix
yr = (x[10:lastrow-4,3]+x[9:lastrow-5,3]+x[8:lastrow-6,3]+x[7:lastrow-7,3])/4;
xr = x[6:lastrow-4,3]~x[5:lastrow-5,3]~x[4:lastrow-6,3]~ones(lastrow-9,1);

i = 1;
do while i <= lastrow-52;
beta = invpd(xr[i:i+39,.]'xr[i:i+39,.])*xr[i:i+39,.]'yr[i:i+39]; //reg yr on xr
x[48+i,4] = xr[i+43,.]*beta; //for 1960.1 onward
i = i+1;
endo;

// 1948.1 - current
// Column 1: XGDP (1948.1-present)
// Column 2: PCNIA spliced with PCXFE (1948.3-present)
// Column 3: Inflation expectations (1960.1-present)
// Column 4: POIL spliced with IMPPETROL (1949.1-present)
// Column 5: PMO spliced with IMPXCOMP (1956.2-present)
// Column 6: NYFRB spliced with RFFE (1948.1-present)
y = x[.,1]~x[.,3:7];
y;

output off;
screen on;

end;

 

Thank you very much!!!


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.