Hi guys,
I'm trying to replicate the results from the heckprob command with a ml model. Following the blogpost here (https://blog.stata.com/2015/10/22/pr...tion-by-mlexp/) it was quite easy to imitate the results with the mlexp command, but I'm not getting them with the usual ml model. Using help heckprob is no help because even though they explain which maximum likelihood function is behind the command, they do not explain how to code it.
So let's assume we have a binary selection equation:
y1 = a0 + a1*z+u
and a binary equation of interest (probit model)
y2 = b0 + b1*x+v
If y1==0, we do not observe y2. u and v are correlated (correlation rho).
We can estimate the a0, b0, a1 and b1 easily with:
or (like in the blog post) with the mlexp command using the following expression:
However, I'm trying to get the same result with a maximum likelihood estimation. Essentially, I'm trying to write the expression above for the ml model command.
This is what I have come up with:
But it doesn't give the correct values. Something is probably wrong in the model, but I have a hard time finding what exactly. All tips are welcome.
Thanks!
I'm trying to replicate the results from the heckprob command with a ml model. Following the blogpost here (https://blog.stata.com/2015/10/22/pr...tion-by-mlexp/) it was quite easy to imitate the results with the mlexp command, but I'm not getting them with the usual ml model. Using help heckprob is no help because even though they explain which maximum likelihood function is behind the command, they do not explain how to code it.
So let's assume we have a binary selection equation:
y1 = a0 + a1*z+u
and a binary equation of interest (probit model)
y2 = b0 + b1*x+v
If y1==0, we do not observe y2. u and v are correlated (correlation rho).
We can estimate the a0, b0, a1 and b1 easily with:
Code:
heckprob y2 x , sel(y1=z)
Code:
mlexp (ln(cond(y1,cond(y2,binormal({y2:x _cons},{y1:z _cons}, {rho}),binormal(-{y2:},{y1:}, -{rho})),1-normal({y1:}))))
This is what I have come up with:
Code:
program define mlheck args lnf Xb Za rho quietly replace `lnf' = ln(binormal(`Xb',`Za',`rho')) if $ML_y1==1 & $ML_y2==1 quietly replace `lnf' = ln(binormal(-`Xb',`Za', -`rho')) if $ML_y1==1 & $ML_y2==0 quietly replace `lnf' = ln(1-normal(`Za')) if $ML_y1==0 end ml model lf mlheck (Y2: y2 = x)(Y1: y1 =z)(Rho:) ml search, repeat(1000) ml maximize
Thanks!
Comment