Write these functions (you have to fix syntax and fill in details):
probit(const beta2, const adFunc, const avScore, const amHessian) {
// Returns the probit likelihood function for equation (3).
// Supply the data through global variables.
decl pb;
pb = probn(-X2*beta2);
return (pb).^m (1-pb).^(1-m) ???;
}
imill(const d) {
//d a column vector
//Return a column vector of corresponding inverse Mill's ratios.
return -densn(d) ./ (1-probn(d)) ???;
}
vfiml(const theta) {
// compute the full information likelihood function for the model (1)-(6)
// return N x 1 vector containing the likelihood for each observation.
// Supply the data through global variables.
pb = probn();
dn = ???;
return pb .* dn ???;
}
numfd(const func,const theta,const gmatrix) {
// theta is k x 1
// func(theta) is Nx1
// gmatrix on output contains the is N x k matrix of
// numerical first derivatives of func.
// get gradient step length from a global variable (eps2?)
return ;
}
fiml(const theta,const like, const Score, const BHHH) {
// return likelihood, score and hessian for the model (1)-(6)
vlk = vfiml(const theta);
like=sumc(vlk);
if (Score!=0) or (BHHH!=0) {
numfd(vfiml,theta,gmat);
if Score!=0 { &Score=sumc(gmat) };
if BHHH!=0 { &BHHH = gmat' * gmat};
};
return 1 ???;
}
hecklee(const fiml, const y,const m, const X,const s,const theta, const vhtheta) {
// If fiml=0 return the Heckman two-step estimates of theta.
// If fiml=1 then return the full-information maximium likelihood estimates of theta
// and the BHHH estimates of its variance matrix.
// (Of course estimates of the variance should be returned in the two-step casee,
// but this is left as optional.)
process the input vectors
get starting values for beta2. (use OLSC?)
MaxBFGS(probit, beta2, lkmax, 0, 0)
lamhat = imilla(-X2*beta2)
olsc(y, X1~lamhat, beta1star, xxinv)
&theta = stuff from beta2, beta1star, and xxinv.
if fiml=1 {
use theta from the 2-step method as starting values to maximize fiml().
use some combination of MaxSimplex(), MaxBFGS(), and MaxNewton().
&BHHH = BHHH estimate of the variance matrix.
}
return 1(?)
}