dlibrary c:\forgau95\Bolib\release\Bolib.dll;

PROC(2)=lad_for(y,x,bst,para);

/*  This routine calculates the the quantile regression estimator using the
    method described in Buchensky (1992)

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variables
        bst     (k x 1)     starting value
        para    (1 x 1)     quantile

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

local a,e,s,ico,n,np,best,th;

y=y-x*bst;
np=cols(x);
n=rows(y);
th=ones(n,1)*para[1];
ico=0; e=zeros(n,1); s=zeros(n,1);
a=zeros(np+2,n+2);
a[1:np,1:n]=x';
best=zeros(np,1);

dllcall boladth(y,a,n,np,best,e,s,ico,th);
RETP(best+bst,ico.eq 2);
ENDP;

PROC(2)=jimbo_c1(y,x,bst,para);

/*  This routine calculates one estimator from Honore and Powell (1992).
    The estimator is the estimator for the censored regression model with
    absolute value loss function.
    The method is a modification of the linear programming method for LAD
    discussed by for example Buchinsky (1992).

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        bst     (k x 1)     starting value
        para    (1 x 1)     not presently used

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

local np,npa,nr,a1,a2,a,best,xb,yo,c,ico,e,s,n,t1;

np=rows(bst);
n=rows(y);
npa=sumc(y.eq 0); npa=(n*(n-1)-npa*(npa-1))/2;
nr=npa;
a2=np+2; a1=nr+2;
a=zeros(a2,a1);
xb=zeros(n,1);
yo=zeros(npa,1);
c=zeros(npa,1);
dllcall boprep(npa,x,y,n,bst,np,a,yo,c,a1,a2,xb);
clear xb;
ico=0; e=zeros(nr,1); s=zeros(nr,1);
best=zeros(np,1);
dllcall boladth(yo,a,nr,np,best,e,s,ico,c);
RETP(best+bst,ico.eq 2);
ENDP;


PROC(2)=jimbo_t1(y,x,best,para);

/*  This routine calculates the STLS estimator for the truncated regression
    model from Honore and Powell (1992) under absolute loss.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (2 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,xb,bdif,xx,n,maxit,mbdif,k,nn,nx,io;
    maxit=para[1];
    mbdif=para[2];
    bdif=mbdif+1;
    iter=0;
    n=rows(x);
    nx=cols(x);
    nn=n*(n-1)/2;
    do while iter <=maxit;
    iter=iter+1;
    b=best;
    k=0;
    yy=zeros(nn,1); xx=zeros(nn,nx); xb=zeros(n,1);
    dllcall botrpr(y,x,nx,nn,n,yy,xx,b,xb,k);
    if (k.eq.0); goto xxx; endif;
    yy=yy[1:k,.]; xx=xx[1:k,.];
    if (rows(xx).lt cols(xx));
      iter=maxit+1;
      goto xxx;
    endif;
    {best,io}=lad_for(yy,xx,b,0.5);
    bdif=sqrt(meanc((b-best).^2));
    if (bdif.<=mbdif); goto xxx; endif;
    endo;
xxx:
RETP(best,bdif.le mbdif);
ENDP;



PROC(2)=jimbo_t2(y,x,best,para);

/*  This routine calculates the STLS estimator for the truncated regression
    model from Honore and Powell (1992) under quadratic loss.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (2 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,xb,bdif,xx,n,maxit,mbdif,k,nn,nx;
    maxit=para[1];
    mbdif=para[2];
    bdif=mbdif+1;
    iter=0;
    n=rows(x);
    nx=cols(x);
    nn=n*(n-1)/2;
    do while iter <=maxit;
    iter=iter+1;
    b=best;
    k=0;
    yy=zeros(nn,1); xx=zeros(nn,nx); xb=zeros(n,1);
    dllcall botrpr(y,x,nx,nn,n,yy,xx,b,xb,k);
    if (k.eq.0); goto xxx; endif;
    yy=yy[1:k,.]; xx=xx[1:k,.];
    if (rows(xx).lt cols(xx));
      iter=maxit+1;
      goto xxx;
    endif;
    best=yy/xx;
    bdif=sqrt(meanc((b-best).^2));
    if (bdif.<=mbdif); goto xxx; endif;
    endo;
xxx:
RETP(best,bdif.le mbdif);
ENDP;


PROC(2)=bucjam(y,x,best,para);

/*  This routine calculates the estimator from Buckley and James (19??) for the
    censored regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (2 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,ee,dd,ou1,ou2,fp,fm,met,mxb,bdif,zz,n,maxit,mbdif;
    maxit=para[1];
    mbdif=para[2];
    iter=0;
    n=rows(y);
xxx:
    iter=iter+1;
    b=best;
    ee=(y-x*b)~(y.>0);
    ee=sortc(ee,1);
    dd=ee[.,2];
    ee=ee[.,1];
    met=1;
    fm=zeros(n,1);
    fp=zeros(n,1);
    ou1=zeros(n,1);
    ou2=zeros(n,1);
    mxb=-x*b;
    dllcall bokapm(n,ee,dd,mxb,fm,fp,ou1,ou2,met);
    yy=y+(y.eq 0).*(-mxb+(ou1./(ou2+y)));
    best=yy/x;
    bdif=sqrt(meanc((b-best).^2));
    if (iter.<maxit).and (bdif.>mbdif);
    goto xxx;
    endif;
RETP(best,bdif.le mbdif);
ENDP;

PROC(2)=stls(y,x,best,para);

/*  This routine calculates the STLS estimator for the censored regression
    model from Powell (1986).

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (2 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,xb,bdif,xx,n,maxit,mbdif,ii;
    maxit=para[1];
    mbdif=para[2];
    iter=0;
    n=rows(x);
    do while iter <=maxit;
    iter=iter+1;
    b=best;
    xb=x*b;
    yy=selif(minc((y~(2*xb))'),xb.>0);
    xx=selif(x,xb.>0);
    if (rows(xx).lt cols(xx));
      iter=maxit+1;
      goto xxx;
    endif;
    best=yy/xx;
    bdif=sqrt(meanc((b-best).^2));
    if (bdif.<=mbdif); goto xxx; endif;
    endo;
xxx:
RETP(best,bdif.le mbdif);
ENDP;

PROC(2)=stls_t(y,x,best,para);

/*  This routine calculates the STLS estimator for the truncated regression
    model from Powell (1986).

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (2 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,xb,bdif,xx,n,maxit,mbdif;
    maxit=para[1];
    mbdif=para[2];
    iter=0;
    n=rows(x);
    do while iter <=maxit;
    iter=iter+1;
    b=best;
    xb=x*b;
    yy=selif(y,(xb.>0).*(y.lt 2*xb));
    xx=selif(x,(xb.>0).*(y.lt 2*xb));
    if (rows(xx).lt cols(xx));
      iter=maxit+1;
      goto xxx;
    endif;
    best=yy/xx;
    bdif=sqrt(meanc((b-best).^2));
    if (bdif.<=mbdif); goto xxx; endif;
    endo;
xxx:
RETP(best,bdif.le mbdif);
ENDP;

PROC(2)=clad(y,x,best,para);

/*  This routine calculates the CLAD and censored quantile regression
    estimator from Powell (1986).

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (3 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter
                            para[3]=quantile

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,xb,bdif,xx,n,maxit,mbdif,th,ico,bold,ii,dif;
    maxit=para[1];
    mbdif=para[2];
    th=para[3];
    iter=0;
    n=rows(x);
    do while iter <=maxit;
    iter=iter+1;
    b=best;
    if (iter.eq 1); bold=best; else; bold=bold~best; endif;
    xb=x*b;
    yy=selif(y,xb.ge 0);
    xx=selif(x,xb.ge 0);
    if (rows(xx).lt cols(xx));
      bdif=mbdif+1;
      goto xxx;
    endif;
    {best,ico}=lad_for(yy,xx,b,th);
    bdif=sqrt(minc(meanc((bold-best).^2)));
    if (bdif.<=mbdif); goto xxx; endif;
    endo;
xxx:
    ii=minindc(meanc((bold-best).^2));
    bold=bold[.,ii:cols(bold)]~best;
    ii=minindc(funclad(y,x,bold));
    best=bold[.,ii];
RETP(best,bdif.le mbdif);
ENDP;

PROC(2)=clad_t(y,x,best,para);


/*  This routine calculates the STLAD estimator for the truncated regression
    model from Powell (198?).

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable
        best     (k x 1)     starting value
        para    (2 x 1)     para[1]=maximum number of iterations
                            para[2]=maximum change in parameter

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

    local iter,yy,b,xb,bdif,xx,n,maxit,mbdif,ico,th;
    maxit=para[1];
    mbdif=para[2];
    th=0.5;
    iter=0;
    n=rows(x);
    do while iter <=maxit;
    iter=iter+1;
    b=best;
    xb=x*b;
    yy=selif(y,(xb.>0).*(y.lt 2*xb));
    xx=selif(x,(xb.>0).*(y.lt 2*xb));
    if (rows(xx).lt cols(xx));
      iter=maxit+1;
      goto xxx;
    endif;
    {best,ico}=lad_for(yy,xx,b,th);
    bdif=sqrt(meanc((b-best).^2));
    if (bdif.<=mbdif); goto xxx; endif;
    endo;
xxx:
RETP(best,bdif.le mbdif);
ENDP;

PROC(2)=fixef(y1,y2,x1,x2,bst,para);

/*  This routine calculates the split sample estimator from Honore
    and Powell (1992) for the censored regression model with absolute
    value loss.

    Inputs:
        y1      (n x 1)     dependent variable in sample 1
        y2      (n x 1)     dependent variable in sample 2
        x1      (n x k)     independent variable in sample 1
        x2      (n x k)     independent variable in sample 2
        bst     (k x 1)     starting value
        para    (1 x 1)     not presently used

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

local yd,d1,d2,d3,d4,c,cm,cp,a,e,s,ico,n,np,best,X,y;
yd=y1-y2;
yd=yd-(x1-x2)*bst;

d1=(y1.gt 0).*(y2.gt 0);
d3=(y1.gt 0).*(y2.eq 0);
d2=(y1.eq 0).*(y2.gt 0);
d4=(y1.eq 0).*(y2.eq 0);

y =selif(yd,1-d4);
X =selif(x1-x2,1-d4);
d1=selif(d1,1-d4);
d2=selif(d2,1-d4);
d3=selif(d3,1-d4);

c  = 0.5*(1-d2);
cm = 0.5*(1-d3);
cp=c+cm;
c=c./cp;
X=X*~cp;
y=y*~cp;

np=rows(bst);
n=rows(y);
ico=0; e=zeros(n,1); s=zeros(n,1);
a=zeros(np+2,n+2);
a[1:np,1:n]=X';
best=zeros(np,1);
dllcall boladth(y,a,n,np,best,e,s,ico,c);
RETP(best+bst,ico.eq 2);
ENDP;

PROC f_hp_c1(y,x,b);

/*  This routine calculates the function value of the objective function
    in Honore and Powell (1992) under absolute loss for the censored
    regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x 1)     parameter value

    Outputs:
        (1)     (1 x 1)     function value
 */
    local xb,f,n,nm;
    n=rows(x);
    xb=x*b;
    f=0;
    nm=2;
    dllcall bocen(y,xb,n,f,nm);
    RETP(f);
ENDP;

PROC f_hp_c2(y,x,b);

/*  This routine calculates the function value of the objective function
    in Honore and Powell (1992) under quadratic loss for the censored
    regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x 1)     parameter value

    Outputs:
        (1)     (1 x 1)     function value
 */

    local xb,f,n,nm;
    n=rows(x);
    xb=x*b;
    f=0;
    nm=1;
    dllcall bocen(y,xb,n,f,nm);
    RETP(f);
ENDP;

PROC f_hp_t1(y,x,b);

/*  This routine calculates the function value of the objective function
    in Honore and Powell (1992) under absolute loss for the truncated
    regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x 1)     parameter value

    Outputs:
        (1)     (1 x 1)     function value
 */
    local xb,f,n,nm;
    n=rows(x);
    xb=x*b;
    f=0;
    nm=2;
    n=rows(x);
    xb=x*b;
    f=0;
    nm=2;
    dllcall botru(y,xb,n,f,nm);
    n=rows(x);
    xb=x*b;
    f=0;
    nm=2;
    dllcall botru(y,xb,n,f,nm);
    n=rows(x);
    xb=x*b;
    f=0;
    nm=2;
    dllcall botru(y,xb,n,f,nm);
    dllcall botru(y,xb,n,f,nm);
    RETP(f);
ENDP;

PROC f_hp_t2(y,x,b);

/*  This routine calculates the function value of the objective function
    in Honore and Powell (1992) under quadratic loss for the truncated
    regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x 1)     parameter value

    Outputs:
        (1)     (1 x 1)     function value
 */
    local xb,f,n,nm;
    n=rows(x);
    xb=x*b;
    f=0;
    nm=1;
    dllcall botru(y,xb,n,f,nm);
    RETP(f);
ENDP;


PROC df_hp_d1(y,x,b);

/*  This routine calculates the function value of the "derivative" of the
    objective function in Honore and Powell (1992) under absolute loss for the
    censored regression model.
    The objective function is not diferentiable. This is a linear combination
    of left and right derivatives.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x 1)     parameter value

    Outputs:
        (1)     (k x 1)     derivatives
 */

    local xb,n,df,xk,nm;

    n=rows(x);
    xk=cols(x);
    df=zeros(xk,1);
    xb=x*b;
    nm=2;
    dllcall bodcen(y,xb,x,n,df,xk,nm);
    RETP(df);
ENDP;

PROC df_hp_d2(y,x,b);

/*  This routine calculates the function value of the derivative of the
    objective function in Honore and Powell (1992) under quadratic loss
    for the censored regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x 1)     parameter value

    Outputs:
        (1)     (k x 1)     derivatives
 */

    local xb,n,df,xk,nm;

    n=rows(x);
    xk=cols(x);
    df=zeros(xk,1);
    xb=x*b;
    nm=1;
    dllcall bodcen(y,xb,x,n,df,xk,nm);
    RETP(df);
ENDP;


PROC funclad(y,x,b);

/*  This routine calculates the function value of the objective function
    Powell's (1984) CLAD estimator.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x p)     matrix of parameter values; each column represents
                            one parameter value

    Outputs:
        (1)     (p x 1)     function values
 */

    local xb,f,nn,nx,nb;
    nn=rows(x);
    nx=cols(x);
    nb=cols(b);
    f=zeros(nb,1);
    dllcall boclad(y,x,nn,nx,nb,b,f);
    RETP(f);
ENDP;

PROC funstls(y,x,b);

/*  This routine calculates the function value of the objective function
    Powell's (1986) STLS estimator of the censored regression model.

    Inputs:
        y       (n x 1)     dependent variable
        x       (n x k)     independent variable (not including constant)
        b       (k x p)     matrix of parameter values; each column represents
                            one parameter value

    Outputs:
        (1)     (p x 1)     function values
 */

    local xb,f,nn,nx,nb;
    nn=rows(x);
    nx=cols(x);
    nb=cols(b);
    f=zeros(nb,1);
    dllcall bostls(y,x,nn,nx,nb,b,f);
    RETP(f);
ENDP;

PROC(3)=typ3_a(y,x,w,z,bst,gst,para);

/*  This routine calculates the estimator from Honore et al (1992) for the
    type tobit model.
    The method is a modofication of the linear programming method for LAD
    discussed by for example Buchinsky (1992).

    Inputs:
        y       (n x 1)     dependent variable (eq 1)
        x       (n x k1)    independent variable (not incl. constant) (eq 1)
        w       (n x 1)     dependent variable (eq 2)
        z       (n x k2)    independent variable (not incl. constant) (eq 2)
        bst     (k1 x 1)    starting value (eq 1)
        gst     (k2 x 1)    starting value (eq 2)
        para    (1 x 1)     not presently used

    Outputs:
        (1)     (k1 x 1)    parameter estimates (eq 1)
        (2)     (k2 x 1)    parameter estimates (eq 2)
        (3)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

local bhat,ico1,yy,np,npa,nr,a1,a2,a,gest,zg,xb,wo,c,ico,e,s,n,t1,zz,ww;

{bhat,ico1}=jimbo_c1(y,x,bst,para);
xb=x*bhat;
yy=selif(y,y.>0);
xb=selif(xb,y.>0);
zz=selif(z,y.>0);
ww=selif(w,y.>0);
n=rows(yy);
if (n.lt 2); RETP(bhat,0*gst,0); endif;
npa=0;
dllcall boprep1a(yy,xb,n,npa);
np=rows(gst);
nr=npa;
a2=np+2; a1=nr+2;
a=zeros(a2,a1);
zg=zeros(n,1);
wo=zeros(npa,1);
c=zeros(npa,1);
dllcall boprep1b(npa,yy,xb,ww,zz,n,gst,np,a,wo,c,a1,a2,zg);
clear xb,zg,yy,ww,zz;
ico=0; e=zeros(nr,1); s=zeros(nr,1);
gest=zeros(np,1);
dllcall boladth(wo,a,nr,np,gest,e,s,ico,c);
RETP(bhat,gest+gst,(ico.eq 2)*ico1);
ENDP;

PROC(2)=chekbo1(y,x1,x2,bst,para);

/*  This routine calculates the first step estimator from Honore et al (1992)
    for Udrys model.
    The method is a modification of the linear programming method for LAD
    discussed by for example Buchinsky (1992).

    Inputs:
        y       (n x 1)     dependent variable
        x1      (n x k)     independent variable (not including constant)
        x2      (n x k)     independent variable (not including constant)
        bst     (k x 1)     starting value
        para    (1 x 1)     not presently used

    Outputs:
        (1)     (k x 1)     parameter estimates
        (2)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

local np,npa1,npa2,nr,a1,a2,a,best,xb,yo,c,ico,e,s,n,t1,y1,y2,yy,xx,g;

np=rows(bst);
n=rows(y);
y1=y.*(y.gt 0);
y2=-y.*(y.lt 0);
yy=y1|y2;
xx=x1|(-x2);
g=ones(n,1)|(2*ones(n,1));
npa1=sumc(y1.eq 0); npa1=(n*(n-1)-npa1*(npa1-1))/2;
npa2=sumc(y2.eq 0); npa2=(n*(n-1)-npa2*(npa2-1))/2;
nr=npa1+npa2;
a2=np+2; a1=nr+2;
a=zeros(a2,a1);
xb=zeros(n,1);
yo=zeros(nr,1);
c=zeros(nr,1);
dllcall boprep2(nr,xx,yy,g,n,bst,np,a,yo,c,a1,a2,xb);
clear xb;
ico=0; e=zeros(nr,1); s=zeros(nr,1);
best=zeros(np,1);
dllcall boladth(yo,a,nr,np,best,e,s,ico,c);
RETP(best+bst,ico.eq 2);
ENDP;

PROC(3)=chekbo(y,x1,x2,w,z1,z2,bst,gst,para);

/*  This routine calculates the pairwise difference estimator from
    Honore et al (1992).
    The method is a modofication of the linear programming method for LAD
    discussed by for example Buchinsky (1992).

    Inputs:
        y       (n x 1)     dependent variable (eq 1)
        x1      (n x k1)    independent variable (not incl. constant) (eq 1)
        x2      (n x k1)    independent variable (not incl. constant) (eq 1)
        w       (n x 1)     dependent variable (eq 2)
        z1      (n x k2)    independent variable (not incl. constant) (eq 2)
        z2      (n x k2)    independent variable (not incl. constant) (eq 2)
        bst     (k1 x 1)    starting value (eq 1)
        gst     (k2 x 1)    starting value (eq 2)
        para    (1 x 1)     not presently used

    Outputs:
        (1)     (k1 x 1)    parameter estimates (eq 1)
        (2)     (k2 x 1)    parameter estimates (eq 2)
        (3)     (1 x 1)     logical whick equals 1 if estimation is successful
 */

local bhat,ico1,y1,y2,np,npa1,npa2,npa,nr,a1,a2,a,gest,zg,
      xb1,xb2,wo,c,ico,e,s,n,t1,zz1,zz2,w1,w2,n1,n2,g;

{bhat,ico1}=chekbo1(y,x1,x2,bst,para);
xb1=x1*bhat;
y1=selif(y,y.>0);
xb1=selif(xb1,y.>0);
zz1=selif(z1,y.>0);
w1=selif(w,y.>0);
n1=rows(y1);

xb2=x2*bhat;
y2=-selif(y,y.<0);
xb2=-selif(xb2,y.<0);
zz2=selif(z2,y.<0);
w2=selif(w,y.<0);
n2=rows(y2);

if ((n1.lt 2).or (n2.lt 2)); RETP(bhat,0*gst,0); endif;
npa1=0; npa2=0;
dllcall boprep1a(y1,xb1,n1,npa1);
dllcall boprep1a(y2,xb2,n2,npa2);
y1=y1|y2; clear y2;
xb1=xb1|xb2; clear xb2;
w1=w1|w2; clear w2;
zz1=zz1|zz2; clear zz2;
g=ones(n1,1)|(2*ones(n2,1));
n=n1+n2;
npa=npa1+npa2;
np=rows(gst);
nr=npa;
a2=np+2; a1=nr+2;
a=zeros(a2,a1);
zg=zeros(n,1);
wo=zeros(npa,1);
c=zeros(npa,1);
dllcall boprep2a(npa,y1,xb1,g,w1,zz1,n,gst,np,a,wo,c,a1,a2,zg);
clear xb1,zg,y1,w1,zz1,g;
ico=0; e=zeros(nr,1); s=zeros(nr,1);
gest=zeros(np,1);
dllcall boladth(wo,a,nr,np,gest,e,s,ico,c);
RETP(bhat,gest+gst,(ico.eq 2)*ico1);
ENDP;



