Help writing codes for a user-written procedure

Dear Sir/Madam

I obtained some Gauss codes for a procedure written by the authors of a recently published paper.

I have tried to write the codes to call and implement this user-written procedure. However, since I am not a expert coder and I have been having difficulties. I should be grateful if someone could kindly help me get operational with my codes. I have included both the code file I wrote (hadri-coint-code) and the user-written procedure (ectj12054-sup-0002-panel_coint.src).

Thanks in advance.


M Shafiullah


//Clear all matrices and data from workspace

library coint, pgraph;
#include ectj12054-sup-0002-panel_coint.src;

//Load in data
load x[2000,3]=xvar.txt;
load c[2000,1]=cvar.txt;
load y[2000,1]=yvar.txt;

// Call Hadri et al. procedure

// Print output
print "sk2 = " sk2;



This is a Gauss code for panel cointegration test proposed by

Hadri, K., E. Kurozumi and Y. Rao (2015) "Novel Panel Cointegration Tests
Emending for Cross-Section Dependence with N Fixed"
(accepted by Econometrics Journal)

This version: March 26, 2014
The code was made by Eiji Kurozumi and Yao Rao
/* -----------------------------------------------------------------------
** Gauss code for panel cointegration test
** format {Sk1,Sk2}=panel_coint(y,x,c,px_all,pc_all,k_ld,k_lg,bw,kp);
** input y: regressand (N by T)
** x: I(1) regressors ( (px1+...+pxN) by T)
** This code allows for each i to have the different
** number of I(1) regressors;
** for i=1, the dimension of x_1t is px1,
** for i=2, it is px2, ..., for i=N, it is pxN
**` c: nonstochastic regressors (pc1+...+pcN) by T)
** This code allows for each i to have different
** nonstochastic regressors;
** for i=1, the dimension of c_1t is pc1,
** for i=2, it is pc2, ..., for i=N, it is pcN
** px_all: =[px1,px2,...,pxN] (1 by N)
** pc_all: =[pc1,pc2,...,pcN] (1 by N)
** k_ld: length of leads for DOLS
** k_lg: length of lags for DOLS
** bw: bandwidth for the Bartlett kernel
** kp: the lag order of autocovariance
** (a_{kt}=eta_{t}eta_{t-Kp})
** output Sk1: the test statistic (without the bias correction)
** Sk2: the test statistic (with bias correction)
** -----------------------------------------------------------------------*/
proc (2) = panel_coint(y,x,c,px_all,pc_all,k_ld,k_lg,bw,kp);
    local N,a_k,bias,i_x,i_c,i_n,y_i,x_i,c_i,w,param_est,eta_est,lrv_e,std_e;
    local nob_e,C_k,omega_ak,Sk1,Sk2;
    N = rows(y);
    a_k = 0;
    bias= 0;
    i_x = 0;
    i_c = 0;
    i_n = 1;
    do until i_n > N;
        y_i = y[i_n,.];
        x_i = x[(i_x+1):(i_x+px_all[1,i_n]),.];
        c_i = c[(i_c+1):(i_c+pc_all[1,i_n]),.];
        @ dols @
        {w,param_est,eta_est} = dols(y_i,x_i,c_i,k_ld,k_lg);
        @ bias @
        lrv_e = lrv_bart(eta_est,bw);
        std_e = stdc(eta_est');
        bias = bias+(pc_all[1,i_n]+px_all[1,i_n])*lrv_e/std_e^2;
        @ a_k @
        nob_e = cols(eta_est);
        eta_est= eta_est'/std_e;
        a_k = a_k+eta_est[kp+1:nob_e,1].*eta_est[1:nob_e-kp,1];
        i_x = i_x+px_all[1,i_n];
        i_c = i_c+pc_all[1,i_n];
        i_n = i_n+1;
    C_k = sumc(a_k)/sqrt(T-kp);
    omega_ak = lrv_bart(a_k',bw);
    bias = bias/sqrt(T-kp);
    Sk1 = C_k/sqrt(omega_ak);
    Sk2 = (C_k+bias)/sqrt(omega_ak);

/* -----------------------------------------------------------------------
** Gauss code for dynamic OLS
** format {w,param_est,u_est}=dols(y0,x0,c0,k_ld,k_lg);
** input y0: regressand (1 by T)
** x0: I(1) regressors (px by T)
** c0: nonstochastic regressors (pc by T)
** k_ld: length of leads
** k_lg: length of lags
** output w: leads and lags of x(t)-x(t-1)
** (k_ld+k_lg+1 by T-k_ld-k_lg-1)
** param_est: estimate of parameters
** u_est: regression residuals (1 by T)
** -----------------------------------------------------------------------*/

proc (3)=dols(y0,x0,c0,k_ld,k_lg);
    local dx,nob_y0,x,c,y,w,k1,k2,z,param_est,u_est;
    dx = x0[.,2:cols(x0)]-x0[.,1:cols(x0)-1];
    y0 = y0[.,2:cols(y0)];
    x0 = x0[.,2:cols(x0)];
    c0 = c0[.,2:cols(c0)];
    x = x0[.,k_lg+1:nob_y0-k_ld];
    c = c0[.,k_lg+1:nob_y0-k_ld];
    y = y0[.,k_lg+1:nob_y0-k_ld];
    w = dx[.,k_lg+1:nob_y0-k_ld];
    if k_ld > 0;
        do until k1 > k_ld;
            w = dx[.,(k_lg+1)+k1:(nob_y0-k_ld)+k1]|w;
            k1 = k1+1;
    if k_lg > 0;
        k2 = 1;
        do until k2 > k_lg;
            w = w|dx[.,(k_lg+1)-k2:(nob_y0-k_ld)-k2];
            k2 = k2+1;
    z = x|c|w;
    param_est = y*z'invpd(z*z');
    u_est = y-param_est*z;

/* -----------------------------------------------------------------------
** Estimate the LRV by the Bartlett kernel
** format {lrv}=lrv_bart(y,bd);
** input y: k times T matrix (k-dimensional)
** bd: bandwidth
** output lrv: k times k LRV matrix
** -----------------------------------------------------------------------*/

    local nob_t,j_p,ac,lrv;
    nob_t = cols(y);
    lrv = y*y'/nob_t;
    j_p = 1;
    do until j_p > bd;
        ac = y[.,j_p+1:nob_t]*y[.,1:nob_t-j_p]'/nob_t;
        lrv = lrv+(1-j_p/(bd+1))*(ac+ac');
        j_p = j_p+1;

2 Answers


The most obvious problem I see is a few GAUSS variables that are not defined before they are used. For clarity here is a very simple example of the problem:

//Delete all GAUSS variables

c = a + b;

In the above code snippet, we try to define c as the sum of a and b. However, we have never given a value to a or b. GAUSS cannot compute the sum of a and b, if it was not told what the value of a and b are.

In your code on the line below:

// Call Hadri et al. procedure

GAUSS is never told the values of: px_all,pc_all,k_ld, k_lg, bw or kp.

The comment above the definition of the panel_coint procedure explains what these variables represent so that you can set them according to your problem:

  • px_all: =[px1,px2,...,pxN] (1 by N)
  • pc_all: =[pc1,pc2,...,pcN] (1 by N)
  • k_ld: length of leads for DOLS
  • k_lg: length of lags for DOLS
  • bw: bandwidth for the Bartlett kernel
  • kp: the lag order of autocovariance




Dear Sir/Madam

Thank you very much. I will amend the codes accordingly.


M Shafiullah

Your Answer

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 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy