Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Heckman with binary dependent variable & Maximum likelihood.

    Hello,

    I am busy with an assignment. The goal is to estimate the heckman selection model (with a binary dependent variable for y2) using maximum likelihood routine. I have to set up a data generating process (so no actual dataset but an artificial one) (e.g. one “x”, one “z”) and assume that the error terms are bivariate normal with mean zero and unit variance, and a certain correlation ρ. I'm supposed to compute this manually then compare it with the heckprob command. However the maximization step of the ML fails and I get an error message and I'm not sure how to correct it.

    Here is my code:

    *** Generate correlated error terms , correlation coefficient is set to 0.5
    matrix omega=(1, 0.5 \ 0.5, 1)
    matrix list omega

    * use cholesky decomposition to find L (Omega = LL’)
    matrix L=cholesky(omega)
    matrix list L matrix K=L’
    mat list K

    * non-correlated normally distributed errors
    gen w1=invnorm(uniform())
    gen w2=invnorm(uniform())

    * make two correlated error terms v1, v2 out of w1 and w2
    gen v1=w1*K[1,1]+w2*K[2,1]
    gen v2=w1*K[1,2]+w2*K[2,2]
    drop w1 w2
    corr v1 v2

    * We rename the error terms using the notation used
    * earlier when describing this model
    rename v1 u
    rename v2 v

    * generate the latent variable y*
    gen y1star = z + u

    * Generate the y's
    gen y1 = y1star > 0
    tab y1

    replace x = . if y1 != 1
    gen y2star = x + v

    gen y2 = y2star > 0
    replace y2 = . if y1 != 1
    tab y2



    replace y2 = -9999 if y2 == .
    tab y2

    * (log)likelihood function for observation i


    capture program drop mlheck

    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-normprob(`Za')) if $ML_y1==0
    }
    end

    ml model lf mlheck (Y1: y1 = z)(Y2: y2 = x)(Rho

    * Starting values
    ml search, repeat(1000)


    ml maximize


    ***** However this step is not working! I get an error message: "could not calculate numerical derivatives -- discontinuous region with
    *missing values encountered" r(430)
    What does this error mean and how can I correct for it?


    *then I need to compare with heckprob command:
    heckprob y2 x, select(y1 = z)
Working...
X