Error Matrix is not positive define

I am using GAUSS 16. I imported Excel sheet csv file which is showing the print command correctly in Gauss but when Hatemi J code is run then error is shown as above. please suggest how to load the data in directory?

 

 

8 Answers



0



G0121 : Matrix not positive definite



0



Could you post the link from which you downloaded the Hatemi code and the line of code from which the error is occurring?

aptech

1,773


0



https://ideas.repec.org/c/boc/bocode/g00006.html

year LM1 LY OER Inf RIR
1991 6.946687 26.87911 22.74243 13.87025 3.624717
1992 7.090493 26.93248 25.91808 11.78782 9.132749
1993 7.217832 26.9789 30.49329 6.362039 5.814777
1994 7.433667 27.04336 31.37374 10.2115 4.33711
1995 7.59228 27.11637 32.42708 10.22489 5.864178
1996 7.704199 27.18916 35.43317 8.977149 7.792994
1997 7.817887 27.22886 36.31329 7.164254 6.909579
1998 7.936081 27.28886 41.25937 13.23084 5.121276
1999 8.072873 27.37362 43.05543 4.669821 9.191247
2000 8.179166 27.41132 44.94161 4.009434 8.342611
2001 8.28824 27.45843 47.18641 3.684807 8.591449
2002 8.401812 27.49576 48.61032 4.3922 7.907177
2003 8.546045 27.57143 46.58328 3.805866 7.307881
2004 8.700086 27.64768 45.31647 3.767238 4.910135
2005 8.876921 27.73646 44.09998 4.246353 6.248331
2006 9.057976 27.82506 45.30701 6.145522 4.477354
2007 9.205356 27.91856 41.34853 6.369997 6.869183
2008 9.341024 27.95673 43.50518 8.351816 4.277227
2009 9.487859 28.03813 48.40527 10.87739 5.773571
2010 9.643114 28.1358 45.72581 11.9923 -0.59685
2011 9.699682 28.20007 46.67047 8.857845 1.498947
2012 9.790493 28.2532 53.43723 9.312446 2.47352
2013 9.881921 28.3151 58.59785 10.90764 3.865993
2014 9.982731 28.38747 61.02951 6.6495 6.985445
2015 10.09001 28.46453 64.15194 4.906973 8.078282


0



The link and data I posted



0



Which variable do you want to be 'y' and which variables should be 'x'?

aptech

1,773


0



In the model LM1 is dependent variable(Y) and rest are independent(X)



0



I was able to reproduce your report. I can get it to run with a couple of different modifications. The first option is to 1) Remove the LY variable and 2) decrease the number of lags considered to 10. My code before the end statement looks like this

fname = "citdata.csv";
y = loadd(fname, "LM1");
x = loadd(fname, ". - year - LM1 - LY");
obs = rows(y);

n = obs;

model = 4;
lag_choice = 2;
k = 10;
call main(y, x, model, lag_choice, k);
end;

The second way that I can make it run is to 1) Add LY back in the model 2) Change the model number to 3 3) Keep the max lags considered at 10, like this

fname = "citdata.csv";
y = loadd(fname, "LM1");
x = loadd(fname, ". - year - LM1");
obs = rows(y);

n = obs;

model = 3;
lag_choice = 2;
k = 10;
call main(y, x, model, lag_choice, k);
end;

I think that the reason for this is that your data does not have enough observations to estimate all the parameters in model 4. Below is the internal X matrix (called x1 in the code) for model 4 with all variables

1  0  0 26.879 22.742 13.870  3.625      0      0      0      0      0      0      0      0
1  0  0 26.932 25.918 11.788  9.133      0      0      0      0      0      0      0      0
1  0  0 26.979 30.493  6.362  5.815      0      0      0      0      0      0      0      0
1  0  0 27.043 31.374 10.211  4.337      0      0      0      0      0      0      0      0
1  1  0 27.116 32.427 10.225  5.864 27.116 32.427 10.225  5.864      0      0      0      0
1  1  0 27.189 35.433  8.977  7.793 27.189 35.433  8.977  7.793      0      0      0      0
1  1  0 27.229 36.313  7.164  6.910 27.229 36.313  7.164  6.910      0      0      0      0
1  1  0 27.289 41.259 13.231  5.121 27.289 41.259 13.231  5.121      0      0      0      0
1  1  1 27.374 43.055  4.670  9.191 27.374 43.055  4.670  9.191 27.374 43.055  4.670  9.191
1  1  1 27.411 44.942  4.009  8.343 27.411 44.942  4.009  8.343 27.411 44.942  4.009  8.343
1  1  1 27.458 47.186  3.685  8.591 27.458 47.186  3.685  8.591 27.458 47.186  3.685  8.591
1  1  1 27.496 48.610  4.392  7.907 27.496 48.610  4.392  7.907 27.496 48.610  4.392  7.907
1  1  1 27.571 46.583  3.806  7.308 27.571 46.583  3.806  7.308 27.571 46.583  3.806  7.308
1  1  1 27.648 45.316  3.767  4.910 27.648 45.316  3.767  4.910 27.648 45.316  3.767  4.910
1  1  1 27.736 44.100  4.246  6.248 27.736 44.100  4.246  6.248 27.736 44.100  4.246  6.248
1  1  1 27.825 45.307  6.146  4.477 27.825 45.307  6.146  4.477 27.825 45.307  6.146  4.477
1  1  1 27.919 41.349  6.370  6.869 27.919 41.349  6.370  6.869 27.919 41.349  6.370  6.869
1  1  1 27.957 43.505  8.352  4.277 27.957 43.505  8.352  4.277 27.957 43.505  8.352  4.277
1  1  1 28.038 48.405 10.877  5.774 28.038 48.405 10.877  5.774 28.038 48.405 10.877  5.774
1  1  1 28.136 45.726 11.992 -0.597 28.136 45.726 11.992 -0.597 28.136 45.726 11.992 -0.597
1  1  1 28.200 46.670  8.858  1.499 28.200 46.670  8.858  1.499 28.200 46.670  8.858  1.499
1  1  1 28.253 53.437  9.312  2.474 28.253 53.437  9.312  2.474 28.253 53.437  9.312  2.474
1  1  1 28.315 58.598 10.908  3.866 28.315 58.598 10.908  3.866 28.315 58.598 10.908  3.866
1  1  1 28.387 61.030  6.649  6.985 28.387 61.030  6.649  6.985 28.387 61.030  6.649  6.985
1  1  1 28.465 64.152  4.907  8.078 28.465 64.152  4.907  8.078 28.465 64.152  4.907  8.078

If you look at the last 8 columns, there is quite a bit of duplication. We can further verify this by computing the eigenvalues of the moment matrix

eigh(x1'x1);

and we see that two of the eigenvalues are 0 to machine precision

-6.88338e-15
3.528834e-16
 0.001575296
   0.5576492
    1.637366
     4.35006
    9.322446
    17.82491
    35.14636
    89.30171
    467.6783
    691.9221
    2495.155
    7659.815
    180365.8

Below is the code that creates the x1 matrix from the x that you input

if model==3;
    x1=ones(n,1)~dummy1~dummy2~seqa(1,1,n)~x;
elseif model==4;
    x1=ones(n,1)~dummy1~dummy2~x~(dummy1).*x~(dummy2).*x;
elseif model==2;
    x1=ones(n,1)~dummy1~dummy2~x;
endif;

We can see that models 2 and 3 are simpler with less redundancy. Therefore, if either of those models will work for your project, I would recommend that option.

citdata.csv looks like this

year,LM1,LY,OER,Inf,RIR
1991,6.946687,26.87911,22.74243,13.87025,3.624717
1992,7.090493,26.93248,25.91808,11.78782,9.132749
1993,7.217832,26.9789,30.49329,6.362039,5.814777
1994,7.433667,27.04336,31.37374,10.2115,4.33711
1995,7.59228,27.11637,32.42708,10.22489,5.864178
1996,7.704199,27.18916,35.43317,8.977149,7.792994
1997,7.817887,27.22886,36.31329,7.164254,6.909579
1998,7.936081,27.28886,41.25937,13.23084,5.121276
1999,8.072873,27.37362,43.05543,4.669821,9.191247
2000,8.179166,27.41132,44.94161,4.009434,8.342611
2001,8.28824,27.45843,47.18641,3.684807,8.591449
2002,8.401812,27.49576,48.61032,4.3922,7.907177
2003,8.546045,27.57143,46.58328,3.805866,7.307881
2004,8.700086,27.64768,45.31647,3.767238,4.910135
2005,8.876921,27.73646,44.09998,4.246353,6.248331
2006,9.057976,27.82506,45.30701,6.145522,4.477354
2007,9.205356,27.91856,41.34853,6.369997,6.869183
2008,9.341024,27.95673,43.50518,8.351816,4.277227
2009,9.487859,28.03813,48.40527,10.87739,5.773571
2010,9.643114,28.1358,45.72581,11.9923,-0.59685
2011,9.699682,28.20007,46.67047,8.857845,1.498947
2012,9.790493,28.2532,53.43723,9.312446,2.47352
2013,9.881921,28.3151,58.59785,10.90764,3.865993
2014,9.982731,28.38747,61.02951,6.6495,6.985445
2015,10.09001,28.46453,64.15194,4.906973,8.078282

aptech

1,773


0



Thank you very much for your help. I was able to run the program with your help.

Your Answer

8 Answers

0

G0121 : Matrix not positive definite

0

Could you post the link from which you downloaded the Hatemi code and the line of code from which the error is occurring?

0

https://ideas.repec.org/c/boc/bocode/g00006.html

year LM1 LY OER Inf RIR
1991 6.946687 26.87911 22.74243 13.87025 3.624717
1992 7.090493 26.93248 25.91808 11.78782 9.132749
1993 7.217832 26.9789 30.49329 6.362039 5.814777
1994 7.433667 27.04336 31.37374 10.2115 4.33711
1995 7.59228 27.11637 32.42708 10.22489 5.864178
1996 7.704199 27.18916 35.43317 8.977149 7.792994
1997 7.817887 27.22886 36.31329 7.164254 6.909579
1998 7.936081 27.28886 41.25937 13.23084 5.121276
1999 8.072873 27.37362 43.05543 4.669821 9.191247
2000 8.179166 27.41132 44.94161 4.009434 8.342611
2001 8.28824 27.45843 47.18641 3.684807 8.591449
2002 8.401812 27.49576 48.61032 4.3922 7.907177
2003 8.546045 27.57143 46.58328 3.805866 7.307881
2004 8.700086 27.64768 45.31647 3.767238 4.910135
2005 8.876921 27.73646 44.09998 4.246353 6.248331
2006 9.057976 27.82506 45.30701 6.145522 4.477354
2007 9.205356 27.91856 41.34853 6.369997 6.869183
2008 9.341024 27.95673 43.50518 8.351816 4.277227
2009 9.487859 28.03813 48.40527 10.87739 5.773571
2010 9.643114 28.1358 45.72581 11.9923 -0.59685
2011 9.699682 28.20007 46.67047 8.857845 1.498947
2012 9.790493 28.2532 53.43723 9.312446 2.47352
2013 9.881921 28.3151 58.59785 10.90764 3.865993
2014 9.982731 28.38747 61.02951 6.6495 6.985445
2015 10.09001 28.46453 64.15194 4.906973 8.078282
0

The link and data I posted

0

Which variable do you want to be 'y' and which variables should be 'x'?

0

In the model LM1 is dependent variable(Y) and rest are independent(X)

0

I was able to reproduce your report. I can get it to run with a couple of different modifications. The first option is to 1) Remove the LY variable and 2) decrease the number of lags considered to 10. My code before the end statement looks like this

fname = "citdata.csv";
y = loadd(fname, "LM1");
x = loadd(fname, ". - year - LM1 - LY");
obs = rows(y);

n = obs;

model = 4;
lag_choice = 2;
k = 10;
call main(y, x, model, lag_choice, k);
end;

The second way that I can make it run is to 1) Add LY back in the model 2) Change the model number to 3 3) Keep the max lags considered at 10, like this

fname = "citdata.csv";
y = loadd(fname, "LM1");
x = loadd(fname, ". - year - LM1");
obs = rows(y);

n = obs;

model = 3;
lag_choice = 2;
k = 10;
call main(y, x, model, lag_choice, k);
end;

I think that the reason for this is that your data does not have enough observations to estimate all the parameters in model 4. Below is the internal X matrix (called x1 in the code) for model 4 with all variables

1  0  0 26.879 22.742 13.870  3.625      0      0      0      0      0      0      0      0
1  0  0 26.932 25.918 11.788  9.133      0      0      0      0      0      0      0      0
1  0  0 26.979 30.493  6.362  5.815      0      0      0      0      0      0      0      0
1  0  0 27.043 31.374 10.211  4.337      0      0      0      0      0      0      0      0
1  1  0 27.116 32.427 10.225  5.864 27.116 32.427 10.225  5.864      0      0      0      0
1  1  0 27.189 35.433  8.977  7.793 27.189 35.433  8.977  7.793      0      0      0      0
1  1  0 27.229 36.313  7.164  6.910 27.229 36.313  7.164  6.910      0      0      0      0
1  1  0 27.289 41.259 13.231  5.121 27.289 41.259 13.231  5.121      0      0      0      0
1  1  1 27.374 43.055  4.670  9.191 27.374 43.055  4.670  9.191 27.374 43.055  4.670  9.191
1  1  1 27.411 44.942  4.009  8.343 27.411 44.942  4.009  8.343 27.411 44.942  4.009  8.343
1  1  1 27.458 47.186  3.685  8.591 27.458 47.186  3.685  8.591 27.458 47.186  3.685  8.591
1  1  1 27.496 48.610  4.392  7.907 27.496 48.610  4.392  7.907 27.496 48.610  4.392  7.907
1  1  1 27.571 46.583  3.806  7.308 27.571 46.583  3.806  7.308 27.571 46.583  3.806  7.308
1  1  1 27.648 45.316  3.767  4.910 27.648 45.316  3.767  4.910 27.648 45.316  3.767  4.910
1  1  1 27.736 44.100  4.246  6.248 27.736 44.100  4.246  6.248 27.736 44.100  4.246  6.248
1  1  1 27.825 45.307  6.146  4.477 27.825 45.307  6.146  4.477 27.825 45.307  6.146  4.477
1  1  1 27.919 41.349  6.370  6.869 27.919 41.349  6.370  6.869 27.919 41.349  6.370  6.869
1  1  1 27.957 43.505  8.352  4.277 27.957 43.505  8.352  4.277 27.957 43.505  8.352  4.277
1  1  1 28.038 48.405 10.877  5.774 28.038 48.405 10.877  5.774 28.038 48.405 10.877  5.774
1  1  1 28.136 45.726 11.992 -0.597 28.136 45.726 11.992 -0.597 28.136 45.726 11.992 -0.597
1  1  1 28.200 46.670  8.858  1.499 28.200 46.670  8.858  1.499 28.200 46.670  8.858  1.499
1  1  1 28.253 53.437  9.312  2.474 28.253 53.437  9.312  2.474 28.253 53.437  9.312  2.474
1  1  1 28.315 58.598 10.908  3.866 28.315 58.598 10.908  3.866 28.315 58.598 10.908  3.866
1  1  1 28.387 61.030  6.649  6.985 28.387 61.030  6.649  6.985 28.387 61.030  6.649  6.985
1  1  1 28.465 64.152  4.907  8.078 28.465 64.152  4.907  8.078 28.465 64.152  4.907  8.078

If you look at the last 8 columns, there is quite a bit of duplication. We can further verify this by computing the eigenvalues of the moment matrix

eigh(x1'x1);

and we see that two of the eigenvalues are 0 to machine precision

-6.88338e-15
3.528834e-16
 0.001575296
   0.5576492
    1.637366
     4.35006
    9.322446
    17.82491
    35.14636
    89.30171
    467.6783
    691.9221
    2495.155
    7659.815
    180365.8

Below is the code that creates the x1 matrix from the x that you input

if model==3;
    x1=ones(n,1)~dummy1~dummy2~seqa(1,1,n)~x;
elseif model==4;
    x1=ones(n,1)~dummy1~dummy2~x~(dummy1).*x~(dummy2).*x;
elseif model==2;
    x1=ones(n,1)~dummy1~dummy2~x;
endif;

We can see that models 2 and 3 are simpler with less redundancy. Therefore, if either of those models will work for your project, I would recommend that option.

citdata.csv looks like this

year,LM1,LY,OER,Inf,RIR
1991,6.946687,26.87911,22.74243,13.87025,3.624717
1992,7.090493,26.93248,25.91808,11.78782,9.132749
1993,7.217832,26.9789,30.49329,6.362039,5.814777
1994,7.433667,27.04336,31.37374,10.2115,4.33711
1995,7.59228,27.11637,32.42708,10.22489,5.864178
1996,7.704199,27.18916,35.43317,8.977149,7.792994
1997,7.817887,27.22886,36.31329,7.164254,6.909579
1998,7.936081,27.28886,41.25937,13.23084,5.121276
1999,8.072873,27.37362,43.05543,4.669821,9.191247
2000,8.179166,27.41132,44.94161,4.009434,8.342611
2001,8.28824,27.45843,47.18641,3.684807,8.591449
2002,8.401812,27.49576,48.61032,4.3922,7.907177
2003,8.546045,27.57143,46.58328,3.805866,7.307881
2004,8.700086,27.64768,45.31647,3.767238,4.910135
2005,8.876921,27.73646,44.09998,4.246353,6.248331
2006,9.057976,27.82506,45.30701,6.145522,4.477354
2007,9.205356,27.91856,41.34853,6.369997,6.869183
2008,9.341024,27.95673,43.50518,8.351816,4.277227
2009,9.487859,28.03813,48.40527,10.87739,5.773571
2010,9.643114,28.1358,45.72581,11.9923,-0.59685
2011,9.699682,28.20007,46.67047,8.857845,1.498947
2012,9.790493,28.2532,53.43723,9.312446,2.47352
2013,9.881921,28.3151,58.59785,10.90764,3.865993
2014,9.982731,28.38747,61.02951,6.6495,6.985445
2015,10.09001,28.46453,64.15194,4.906973,8.078282

0

Thank you very much for your help. I was able to run the program with your help.


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.