While using R for estimating the Heckman 2-stages model a friend stumbled on a problem. the selection() funtion from the package sampleSelection estimates everything just fine. The code is as follows.
# reading the data
dados <- read.dta("mus16data.dta")
# response variable
y <- dados$ambexp
# the transformation of the response that we mean to model
lny <- log(y)
# the variable that will be the response in the probit stage
dy <- y > 0
# the actual model
model <- selection(dy ~ ins + age + female + educ + blhisp + totchr,
lny ~ age + female + educ + blhisp + totchr + age2, dados)
The estimated covariance matrix for the coefficient estimators is found by calling model$vcov. It agrees with the output from Stata, for example. But when we try to construct the output by "hand" (coding from scratch), using the formulas from the documentation of both R and Stata (which are the same) we do not arrive at the same result as the software. Any hints on what may be wrong? The expressions are actually simple and are seen on Greene's Econometric Analysis in the chapter regarding the models.