error G0152 : Variable not initialized stack trace:

Hi, I want to modify a existing Gauss code and run new (simplified) version, but receive some error message

G:\Blundell_AER\Blundell_AER\md_ARE2.prg(165) : error G0152 : Variable not initialized
Currently active call: fcn [165] G:\Blundell_AER\Blundell_AER\md_ARE2.prg
Stack trace:
fcn called from G:\Blundell_AER\Blundell_AER\md_ARE2.prg, line 90
cov called from c:\gauss10\src\optutil.src, line 151
_optmum called from c:\gauss10\src\optmum.src, line 252
optmum called from G:\Blundell_AER\Blundell_AER\md_ARE2.prg, line 48

The prolem seems due to either I haven't defined some variable correctly or haven't called the optmum library propertly. I'm not sure. At least, after check the relevant part of codes, I failed to find any obvious mistake

{b,fun,grad,ok} = optmum(&cov,b0); // Optimisation procedure  -- line 48---
{dfb} = gradfd(&fcn,b); @ Gradient of covariances at minimum - df/db @

/*Choose weighting matrix*/

ww=invpd(diagrv(zeros(rows(var),cols(var)),diag(var)));
covth=invpd(dfb'*ww*dfb)*dfb'*ww*var*ww*dfb*invpd(dfb'*ww*dfb); @ Covariances of parameters under EWMD, Var(lambda_hat) @

fmn =fcn(b); @ Value of covariances at minimum @
df =rows(m) - rank(dfb); @ Degrees of freedom @
seth =sqrt(diag(covth)); @ Standard Errors @

A=dfb*invpd(dfb'*ww*dfb)*dfb'*ww;
W=eye(rows(A))-A;
mf=(m-fmn)'*pinv(W*var*W')*(m-fmn);
prb =cdfchic(mf,df); @ P-value of the above test @

results=(b~seth)|(mf~prb);
y=saved(results,"G:\\Blundell_AER\\Blundell_AER\\MD_res",0);

output file=c:\papers\partial\revise2\batchres.log on;
print "zt " b[1:T_z]~seth[1:T_z];
print "et " b[1+T_z:T_z+T_e]~seth[1+T_z:T_z+T_e];
print "Chi-sq. " mf~df~prb;

@ Minimum Distance Procedure @
proc cov(b);
    local fmm,f,peso;
    fmm=fcn(b); /*parameterized moment*/   ----line 90-----
        peso=diagrv(zeros(rows(var),cols(var)),diag(var));
    f=(m-fmm)'*invpd(peso)*(m-fmm); @ m is vector of actual covariances - fmm is implied covariances @
    retp(f);
endp;

@ Gradient Procedure - defines implied covariance structure from hypothesised model @

proc fcn(b);
    
    local teta,psit,phit,zt,et,lev,levy,levc,levyc,levaux1,levaux2,lev1,
        j,j1,i,difa1,difa2,fm,levt,levp,L,k,r,varv,
        dify,difcd,difc,difcme,difyc,dif,varcsi,vareta,missing_v;
    teta =0;
    zt =b[1:T_z];
    et =b[1+T_z:T_z+T_e];
    
    dify =zeros(T,T);
    
    /* This is the variance of Income */
    dify[1,1]=zt[1]+et[1]+(1-teta)^2*et[1]+teta^2*et[1];
    dify[2,2]=zt[1]+et[2]+(1-teta)^2*et[1]+teta^2*et[1];
    dify[3,3]=zt[1]+et[3]+(1-teta)^2*et[2]+teta^2*et[1];
    j=4;
    do while j<=T-3;
        dify[j,j]=zt[j-2]+et[j]+(1-teta)^2*et[j-1]+teta^2*et[j-2]; //when teta=0,we have zt[j-2]+et[j]+et[j-1]
        j=j+1;
    endo;
    dify[T-2,T-2]=zt[T-4]+et[T-2]+(1-teta)^2*et[T-3]+teta^2*et[T-4];
    dify[T-1,T-1]=zt[T-4]+et[T-2]+(1-teta)^2*et[T-2]+teta^2*et[T-3];
    dify[T,T] =zt[T-4]+et[T-2]+(1-teta)^2*et[T-2]+teta^2*et[T-2];
    
    dify[1,2]=-(1-teta)^2*et[1];
    j=3;
    do while j<=T-1;
        dify[j-1,j]=-(1-teta)*et[j-1]+teta*(1-teta)*et[j-2]; /*Identification of transition shock v_t (C2)*/
        j=j+1;
    endo;
    dify[T-1,T-2]=-(1-teta)^2*et[T-2];
    
    j=3;
    do while j<=T;
        dify[j-2,j]=-teta*et[j-2];
        j=j+1;
    endo;
    
    i=2;
    do while i<=T;
        j=i;
        do while j<=T;
            dify[j,i-1]=dify[i-1,j];
            j=j+1;
        endo;
        i=i+1;
    endo;
    /* Final matrix */
    
    dif[1:T,1:T] =dify;
    fm=vech(dif);
    retp(fm);
endp;
end;

3 Answers



0



Looking over the stacktrace and the code, I notice that the first few lines of the procedure fcn are using variables that have not been defined (at least in the code that I see). Towards the top of fcn, in the lines:

zt =b[1:T_z];
et =b[1+T_z:T_z+T_e];
    
dify =zeros(T,T);

I do not see that T_z, T_e or T are defined anywhere. This could be, because I do not have the entire file.

I would recommend that you place a call to fcn with b0 as the input and an end statement right before the call to optmum on line 48, then run the file again.

//Try calling 'fcn' to verify it is working
tmp = fcn(b0);
end;
{b,fun,grad,ok} = optmum(&cov,b0); // Optimisation procedure  -- line 48---
{dfb} = gradfd(&fcn,b); @ Gradient of covariances at minimum - df/db @

This will show us if there is a problem in calling fcn, which I would suspect. It should also provide more straightforward error messages.

aptech

1,773


0



Thanks a lot for your kindly reply. Two responses, firstly, the T_z, T_e or T have been defined in the codes, though not demonstrated in the post (original code is a little bit long). Moreover, when I add the snippet of codes as your suggest, the error message appears

G:\Blundell_AER\Blundell_AER\md_ARE2.prg(168) : error G0152 : Variable not initialized
Currently active call: fcn [168] G:\Blundell_AER\Blundell_AER\md_ARE2.prg
Stack trace:
fcn called from G:\Blundell_AER\Blundell_AER\md_ARE2.prg, line 49

The new code

/* Minimum distance estimation */

new;

ma =0; /* Choose if you want MA(1) for income */
taste =0; /* Choose if you want taste shocks */
varying_ins =0; /* Choose if you want time-varying insurance coeff */

library optmum;
#include optmum.ext;
optset;

open f1=G:\Blundell_AER\Blundell_AER\coh7992;
x =readr(f1,rowsf(f1));
f1 =close(f1);

m =x[.,1]; /*Vector of covariances*/
var =x[.,2:cols(x)-1]; /*Weighting matrix - Variance matrix for optimal mindist,*/

T =x[1,cols(x)]; /*Lenght of the panel (in FD)*/
initial_year=x[3,cols(x)];
final_year =x[4,cols(x)];

T_pz=1+varying_ins;
T_pe=1+varying_ins;
T_e =T-2;
T_z =T-4;
T_u=9;

extra=ma+taste; /* Number of extra parameters*/
@ Starting parameters and model type@

b0 =zeros(T_e+T_z,1);
//b0[extra-1] =-0.1; /*teta, how about b0[-1]? */
//b0[extra] =0.01; /*var csi*/
b0[1:T_z] =0.03*ones(T_z,1); /*variance of the perm shocks*/
b0[1+T_z:T_z+T_e] =0.03*ones(T_e,1); /*variance of the trans shocks*/
//b0[1+T_z+T_e:T_z+T_e+T_pz] =1*ones(T_pz,1); /*coeff of partial insurance perm shock*/
//b0[1+T_z+T_e+T_pz:T_z+T_e+T_pz+T_pe] =0*ones(T_pe,1); /*coeff of partial insurance of trans shock*/
//b0[1+T_z+T_e+T_pz+T_pe:rows(b0)] =0.06*ones(T_u,1); /*variance of meas. error consumption*/

__title = "Error-Components Model";
__row=0;
__miss=1;

//Try calling 'fcn' to verify it is working
tmp = fcn(b0); //-------line49----------
    end;
{b,fun,grad,ok} = optmum(&cov,b0); @ Optimisation procedure @
{dfb} = gradfd(&fcn,b); @ Gradient of covariances at minimum - df/db @

/*Choose weighting matrix*/

ww=invpd(diagrv(zeros(rows(var),cols(var)),diag(var)));
covth=invpd(dfb'*ww*dfb)*dfb'*ww*var*ww*dfb*invpd(dfb'*ww*dfb); @ Covariances of parameters under EWMD, Var(lambda_hat) @

fmn =fcn(b); @ Value of covariances at minimum @
df =rows(m) - rank(dfb); @ Degrees of freedom @
seth =sqrt(diag(covth)); @ Standard Errors @

A=dfb*invpd(dfb'*ww*dfb)*dfb'*ww;
W=eye(rows(A))-A;
mf=(m-fmn)'*pinv(W*var*W')*(m-fmn);
prb =cdfchic(mf,df); @ P-value of the above test @

//insur_est=2~2;

results=(b~seth)|(mf~prb);
y=saved(results,"G:\\Blundell_AER\\Blundell_AER\\MD_res",0);

output file=c:\papers\partial\revise2\batchres.log on;
print "zt " b[1:T_z]~seth[1:T_z];
print "et " b[1+T_z:T_z+T_e]~seth[1+T_z:T_z+T_e];
print "Chi-sq. " mf~df~prb;

output off;

@system;@
end;

/*NOTE: BELOW YOU WILL FIND THE MINIMUM DISTANCE PROC(EDURE) IN CASE YOU WANT TO MODIFY IT
or ACCESS IT*/

@ Minimum Distance Procedure @
proc cov(b);
    local fmm,f,peso;
    fmm=fcn(b); /*parameterized moment*/
    peso=diagrv(zeros(rows(var),cols(var)),diag(var));
    f=(m-fmm)'*invpd(peso)*(m-fmm); @ m is vector of actual covariances - fmm is implied covariances @
    retp(f);
endp;

@ Gradient Procedure - defines implied covariance structure from hypothesised model @

proc fcn(b);
    
    local teta,psit,phit,zt,et,lev,levy,levc,levyc,levaux1,levaux2,lev1,
        j,j1,i,difa1,difa2,fm,levt,levp,L,k,r,varv,
        dify,difcd,difc,difcme,difyc,dif,varcsi,vareta,missing_v;
    
    //k=extra;
    
    //teta =b[k-1]; /*what is interesting is when ma=1 and taste=0, k=ma+taste=1,so teta=b[0]? */
    teta =0;
    //vareta =0;
    //varcsi =b[k];
    zt =b[1:T_z];
    et =b[1+T_z:T_z+T_e];
    //phit =b[1+T_z+T_e+k:T_z+T_e+T_pz+k];
    //psit =b[1+T_z+T_e+T_pz+k:T_e+T_z+T_pe+T_pz+k];
    //varv =b[1+T_z+T_e+T_pz+T_pe+k:T_e+T_z+T_pe+T_pz+k+T_u];
    
    dify =zeros(T,T);
    //difcd =zeros(T,T); /* Consumption */
    //difc =zeros(T,T); /* Consumption */
    //difcme=zeros(T,T); /* Measurement error of consumption */
    //difyc =zeros(T,T);
    //dif =zeros(2*T,2*T);
    
    /* This is the variance of Income */
    dify[1,1]=zt[1]+et[1]+(1-teta)^2*et[1]+teta^2*et[1];
    dify[2,2]=zt[1]+et[2]+(1-teta)^2*et[1]+teta^2*et[1];
    dify[3,3]=zt[1]+et[3]+(1-teta)^2*et[2]+teta^2*et[1];
    j=4;
    do while j<=T-3;
        dify[j,j]=zt[j-2]+et[j]+(1-teta)^2*et[j-1]+teta^2*et[j-2]; //when teta=0,we have zt[j-2]+et[j]+et[j-1]
        j=j+1;
    endo;
    dify[T-2,T-2]=zt[T-4]+et[T-2]+(1-teta)^2*et[T-3]+teta^2*et[T-4];
    dify[T-1,T-1]=zt[T-4]+et[T-2]+(1-teta)^2*et[T-2]+teta^2*et[T-3];
    dify[T,T] =zt[T-4]+et[T-2]+(1-teta)^2*et[T-2]+teta^2*et[T-2];
    
    dify[1,2]=-(1-teta)^2*et[1];
    j=3;
    do while j<=T-1;
        dify[j-1,j]=-(1-teta)*et[j-1]+teta*(1-teta)*et[j-2]; /*Identification of transition shock v_t (C2)*/
        j=j+1;
    endo;
    dify[T-1,T-2]=-(1-teta)^2*et[T-2];
    
    j=3;
    do while j<=T;
        dify[j-2,j]=-teta*et[j-2];
        j=j+1;
    endo;
    
    i=2;
    do while i<=T;
        j=i;
        do while j<=T;
            dify[j,i-1]=dify[i-1,j];
            j=j+1;
        endo;
        i=i+1;
    endo;
    /* Final matrix */
    
    dif[1:T,1:T] =dify; //--------line168----------
        fm=vech(dif);
    retp(fm);
endp;
end;

Thank you.



0



Since the undefined variable is on line 168, which contains:

dif[1:T,1:T] =dify;

then the undefined variable must be either, dif, dify or T.
If you have a recent version of GAUSS, you can click on the variable dif, the right-click and select 'Find Usages'. This will bring up a window with a list of all usages of dif in the file, ordered by line number. If we do this, we see that dif is never assigned any value before the line above try's to assign to it by index.

It looks like you just need to uncomment the line:

//dif =zeros(2*T,2*T);

and this problem should be resolved.

aptech

1,773

Your Answer

3 Answers

0

Looking over the stacktrace and the code, I notice that the first few lines of the procedure fcn are using variables that have not been defined (at least in the code that I see). Towards the top of fcn, in the lines:

zt =b[1:T_z];
et =b[1+T_z:T_z+T_e];
    
dify =zeros(T,T);

I do not see that T_z, T_e or T are defined anywhere. This could be, because I do not have the entire file.

I would recommend that you place a call to fcn with b0 as the input and an end statement right before the call to optmum on line 48, then run the file again.

//Try calling 'fcn' to verify it is working
tmp = fcn(b0);
end;
{b,fun,grad,ok} = optmum(&cov,b0); // Optimisation procedure  -- line 48---
{dfb} = gradfd(&fcn,b); @ Gradient of covariances at minimum - df/db @

This will show us if there is a problem in calling fcn, which I would suspect. It should also provide more straightforward error messages.

0

Thanks a lot for your kindly reply. Two responses, firstly, the T_z, T_e or T have been defined in the codes, though not demonstrated in the post (original code is a little bit long). Moreover, when I add the snippet of codes as your suggest, the error message appears

G:\Blundell_AER\Blundell_AER\md_ARE2.prg(168) : error G0152 : Variable not initialized
Currently active call: fcn [168] G:\Blundell_AER\Blundell_AER\md_ARE2.prg
Stack trace:
fcn called from G:\Blundell_AER\Blundell_AER\md_ARE2.prg, line 49

The new code

/* Minimum distance estimation */

new;

ma =0; /* Choose if you want MA(1) for income */
taste =0; /* Choose if you want taste shocks */
varying_ins =0; /* Choose if you want time-varying insurance coeff */

library optmum;
#include optmum.ext;
optset;

open f1=G:\Blundell_AER\Blundell_AER\coh7992;
x =readr(f1,rowsf(f1));
f1 =close(f1);

m =x[.,1]; /*Vector of covariances*/
var =x[.,2:cols(x)-1]; /*Weighting matrix - Variance matrix for optimal mindist,*/

T =x[1,cols(x)]; /*Lenght of the panel (in FD)*/
initial_year=x[3,cols(x)];
final_year =x[4,cols(x)];

T_pz=1+varying_ins;
T_pe=1+varying_ins;
T_e =T-2;
T_z =T-4;
T_u=9;

extra=ma+taste; /* Number of extra parameters*/
@ Starting parameters and model type@

b0 =zeros(T_e+T_z,1);
//b0[extra-1] =-0.1; /*teta, how about b0[-1]? */
//b0[extra] =0.01; /*var csi*/
b0[1:T_z] =0.03*ones(T_z,1); /*variance of the perm shocks*/
b0[1+T_z:T_z+T_e] =0.03*ones(T_e,1); /*variance of the trans shocks*/
//b0[1+T_z+T_e:T_z+T_e+T_pz] =1*ones(T_pz,1); /*coeff of partial insurance perm shock*/
//b0[1+T_z+T_e+T_pz:T_z+T_e+T_pz+T_pe] =0*ones(T_pe,1); /*coeff of partial insurance of trans shock*/
//b0[1+T_z+T_e+T_pz+T_pe:rows(b0)] =0.06*ones(T_u,1); /*variance of meas. error consumption*/

__title = "Error-Components Model";
__row=0;
__miss=1;

//Try calling 'fcn' to verify it is working
tmp = fcn(b0); //-------line49----------
    end;
{b,fun,grad,ok} = optmum(&cov,b0); @ Optimisation procedure @
{dfb} = gradfd(&fcn,b); @ Gradient of covariances at minimum - df/db @

/*Choose weighting matrix*/

ww=invpd(diagrv(zeros(rows(var),cols(var)),diag(var)));
covth=invpd(dfb'*ww*dfb)*dfb'*ww*var*ww*dfb*invpd(dfb'*ww*dfb); @ Covariances of parameters under EWMD, Var(lambda_hat) @

fmn =fcn(b); @ Value of covariances at minimum @
df =rows(m) - rank(dfb); @ Degrees of freedom @
seth =sqrt(diag(covth)); @ Standard Errors @

A=dfb*invpd(dfb'*ww*dfb)*dfb'*ww;
W=eye(rows(A))-A;
mf=(m-fmn)'*pinv(W*var*W')*(m-fmn);
prb =cdfchic(mf,df); @ P-value of the above test @

//insur_est=2~2;

results=(b~seth)|(mf~prb);
y=saved(results,"G:\\Blundell_AER\\Blundell_AER\\MD_res",0);

output file=c:\papers\partial\revise2\batchres.log on;
print "zt " b[1:T_z]~seth[1:T_z];
print "et " b[1+T_z:T_z+T_e]~seth[1+T_z:T_z+T_e];
print "Chi-sq. " mf~df~prb;

output off;

@system;@
end;

/*NOTE: BELOW YOU WILL FIND THE MINIMUM DISTANCE PROC(EDURE) IN CASE YOU WANT TO MODIFY IT
or ACCESS IT*/

@ Minimum Distance Procedure @
proc cov(b);
    local fmm,f,peso;
    fmm=fcn(b); /*parameterized moment*/
    peso=diagrv(zeros(rows(var),cols(var)),diag(var));
    f=(m-fmm)'*invpd(peso)*(m-fmm); @ m is vector of actual covariances - fmm is implied covariances @
    retp(f);
endp;

@ Gradient Procedure - defines implied covariance structure from hypothesised model @

proc fcn(b);
    
    local teta,psit,phit,zt,et,lev,levy,levc,levyc,levaux1,levaux2,lev1,
        j,j1,i,difa1,difa2,fm,levt,levp,L,k,r,varv,
        dify,difcd,difc,difcme,difyc,dif,varcsi,vareta,missing_v;
    
    //k=extra;
    
    //teta =b[k-1]; /*what is interesting is when ma=1 and taste=0, k=ma+taste=1,so teta=b[0]? */
    teta =0;
    //vareta =0;
    //varcsi =b[k];
    zt =b[1:T_z];
    et =b[1+T_z:T_z+T_e];
    //phit =b[1+T_z+T_e+k:T_z+T_e+T_pz+k];
    //psit =b[1+T_z+T_e+T_pz+k:T_e+T_z+T_pe+T_pz+k];
    //varv =b[1+T_z+T_e+T_pz+T_pe+k:T_e+T_z+T_pe+T_pz+k+T_u];
    
    dify =zeros(T,T);
    //difcd =zeros(T,T); /* Consumption */
    //difc =zeros(T,T); /* Consumption */
    //difcme=zeros(T,T); /* Measurement error of consumption */
    //difyc =zeros(T,T);
    //dif =zeros(2*T,2*T);
    
    /* This is the variance of Income */
    dify[1,1]=zt[1]+et[1]+(1-teta)^2*et[1]+teta^2*et[1];
    dify[2,2]=zt[1]+et[2]+(1-teta)^2*et[1]+teta^2*et[1];
    dify[3,3]=zt[1]+et[3]+(1-teta)^2*et[2]+teta^2*et[1];
    j=4;
    do while j<=T-3;
        dify[j,j]=zt[j-2]+et[j]+(1-teta)^2*et[j-1]+teta^2*et[j-2]; //when teta=0,we have zt[j-2]+et[j]+et[j-1]
        j=j+1;
    endo;
    dify[T-2,T-2]=zt[T-4]+et[T-2]+(1-teta)^2*et[T-3]+teta^2*et[T-4];
    dify[T-1,T-1]=zt[T-4]+et[T-2]+(1-teta)^2*et[T-2]+teta^2*et[T-3];
    dify[T,T] =zt[T-4]+et[T-2]+(1-teta)^2*et[T-2]+teta^2*et[T-2];
    
    dify[1,2]=-(1-teta)^2*et[1];
    j=3;
    do while j<=T-1;
        dify[j-1,j]=-(1-teta)*et[j-1]+teta*(1-teta)*et[j-2]; /*Identification of transition shock v_t (C2)*/
        j=j+1;
    endo;
    dify[T-1,T-2]=-(1-teta)^2*et[T-2];
    
    j=3;
    do while j<=T;
        dify[j-2,j]=-teta*et[j-2];
        j=j+1;
    endo;
    
    i=2;
    do while i<=T;
        j=i;
        do while j<=T;
            dify[j,i-1]=dify[i-1,j];
            j=j+1;
        endo;
        i=i+1;
    endo;
    /* Final matrix */
    
    dif[1:T,1:T] =dify; //--------line168----------
        fm=vech(dif);
    retp(fm);
endp;
end;

Thank you.

0

Since the undefined variable is on line 168, which contains:

dif[1:T,1:T] =dify;

then the undefined variable must be either, dif, dify or T.
If you have a recent version of GAUSS, you can click on the variable dif, the right-click and select 'Find Usages'. This will bring up a window with a list of all usages of dif in the file, ordered by line number. If we do this, we see that dif is never assigned any value before the line above try's to assign to it by index.

It looks like you just need to uncomment the line:

//dif =zeros(2*T,2*T);

and this problem should be resolved.


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