/**********  OLS w/ Jackknife Estimated Variances  **************
Author: Geomina Turlea, PhD student
        Central and East European Economic Research Center, 
        Warsaw Poland and Institute for World Economy, 
        Bucharest, Romania
        mailto:turlea@fx.ro or turlea@ceeerc.wne.uw.edu.pl
Date: 05/15/1999

This code is provided for public, non-comercial use.
There are no performance guarranties.

Feedback and suggestions for extensions are welcome.



MESSAGE FOR THE POTENTIAL USER:
ols_jk() estimates the variance of OLS
coefficients when heteroscedasticity is
encountered using two delete-one jackknifing 
methods proposed by Wu(1986).
This is particularly useful in the field of 
macroeconometric modelling with data from 
transition countries or any short time
series, with unclear properties.

Reference: Wu, C.F.J., "Jackknife, bootstrap and other
resampling plans in regression analysis", Ann.Statist 14/1986,
pp.1261-1350.
(This procedure refers to the case of linear parameters.)

This procedure have been developed during 
author's fellowship at CEEERC,
Warsaw, Poland. 
Financial support gratefully acknowledged.

_____________________________________________________________________

FORMAT: {beta_jk}=ols_jk(y,x,b0)
y: dependent variable
x: matrix of independent variables
b0: 1=intercept included in regression, 0=no intercept
beta_jk: 3 columns matrix with
col.1=b:vector of OLS coefficients
col.2=vh1: matrix[cols(x),cols(x)] - store the variances of parameters
estimated
using the Hinkley weighted modification
col3=vj1: matrix[cols(x),cols(x)] - store the variances of parameters
estimated
using the Wu delete-one weighted jackknife

_______________________________________________________________________
**********************************************************************/

proc(1)=ols_jk(y,x,b0);
local r,w1,w2,vh1,vj1,i,beta_jk;
local vnam,m,b,stb,vc,stderr,sigma,cx,rsq,resid,dwstat;

__output=1;
_olsres=1;

if b0/=0 and b0/=1;
?; "ERROR: Please specify b0 as 1/0 variable!";
stop;
else;
__con=b0;
endif;

"**********************************************************";
"   OLS estimation with jackknifed variance of parameters";
"         APPROPRIATE IN CASE OF HETEROSCEDASTIC ERRORS";
;
"   Method: Wu weighted delete-one jackknife (VJ1) and";
"           Hinkley weighted modification (VH1)";
 "**********************************************************";

{vnam,m,b,stb,vc,stderr,sigma,cx,rsq,resid,dwstat}=ols(0,y,x);

r=resid';   @ retaines the residual vector @

if b0==1;
x=ones(rows(y),1)~x;   @ attach the const to the data set for further
manipulati
on @
endif;

w1=zeros(cols(x),cols(x));   @ for intermediate calculations @
w2=zeros(cols(x),cols(x));

i=1;

do until i>rows(y);

@ for Hinkley modification @
w1=w1+((r[i]^2)/(1-cols(x)/rows(y)))*(x[i,.]'*x[i,.])*inv(x'*x);
@ for Wu weighted jackknife @

w2=w2+((r[i]^2)/(1-x[i,.]*inv(x'*x)*x[i,.]'))*(x[i,.]'*x[i,.])*inv(x'*x);

i=i+1;

endo;

@ HINKLEY MODIFICATION @

vh1 = inv(x'*x)*(w1);

@ WU WEIGHTED DELETE-ONE JACKKNIFE @

vj1 = inv(x'*x)*(w2);

@ Printing the coefficients and jackknifed variances @
;
"------------------------------------------------------";
"  JACKKNIFE ESTIMATED VARIANCES OF PARAMETERS";
"------------------------------------------------------";
"         Beta             VH1             VJ1 ";
"------------------------------------------------------";
beta_jk=b~diag(vh1)~diag(vj1);
retp(beta_jk);
"------------------------------------------------------";

endp;

