Announcement

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

  • Double hurdle model_Problem with programming

    Dear STATA experts,

    Could you please look at my codes and see how should I solve this error? What should be the reason for this problem? I come across with this problem:

    could not calculate numerical derivatives -- discontinuous region with missing values
    encountered



    Below is all my codes.




    .
    . local consvars=" AGELAST FAMS region* marital*"

    .
    . local partvars="AGELAST region* marital*"

    .
    . program doublehurdle_bvn
    1. version 12
    2. args lnf beta alpha_ lnsigma thetat
    3. tempvar sigma F_eps_d F_eps_c f_eps F_u copula deriv_cop theta
    4. qui gen double `theta'=tanh(`thetat')
    5. qui gen double `sigma'=exp(`lnsigma')
    6. qui gen double `F_eps_d'=normal(-`beta'/`sigma')
    7. qui gen double `F_eps_c'=normal(($ML_y1-`beta')/`sigma')
    8. qui gen double `f_eps'=normalden(($ML_y1-`beta')/`sigma')/`sigma'
    9. qui gen double `F_u'=normal(-`alpha_')
    10. qui gen double `copula'=binormal(invnormal(`F_eps_d'),invnormal(` F_u'),`thet
    > a')
    11. qui gen double `deriv_cop'=normal((1-`theta'^2)^(-1/2)*(invnormal(`F_u')-`th
    > eta'*invnormal(`F_eps_c')))
    12. qui replace `lnf'=log(1-binormal(`alpha_',`beta'/`sigma',`theta')) if $ML_y1
    > ==0
    13. qui replace `lnf'=log(normal((`alpha_'+`theta'/`sigma'*($ML_y1-`beta'))/sqrt
    > (1-`theta'^2))*normalden(($ML_y1-`beta')/`sigma')/`sigma') if $ML_y1>0
    14. end

    .
    . ml model lf doublehurdle_bvn (worked=`consvars') (everworked=`partvars') (lnsigma,nocon
    > s) (theta,nocons)
    note: region4 omitted because of collinearity
    note: maritals5 omitted because of collinearity
    note: region4 omitted because of collinearity
    note: maritals5 omitted because of collinearity

    . capture noisily ml maximize, iter(1000)

    initial: log likelihood = -<inf> (could not be evaluated)
    feasible: log likelihood = -32218.061
    rescale: log likelihood = -3456.0122
    rescale eq: log likelihood = -3425.1135
    could not calculate numerical derivatives -- discontinuous region with missing values
    encountered

    . *outreg2 using myreg1.doc, replace addnote(1) e(all)
    .
    .
    . program doublehurdle_gaussian1
    1. version 12
    2. args lnf beta alpha_ lnsigma thetat
    3. tempvar sigma F_eps_d F_eps_c f_eps F_u copula deriv_cop theta
    4. qui gen double `theta'=tanh(`thetat')
    5. qui gen double `sigma'=exp(`lnsigma')
    6. qui gen double `F_eps_d'=normal(-`beta'/`sigma')
    7. qui gen double `F_eps_c'=normal(($ML_y1-`beta')/`sigma')
    8. qui gen double `f_eps'=normalden(($ML_y1-`beta')/`sigma')/`sigma'
    9. qui gen double `F_u'=normal(-`alpha_')
    10. qui gen double `copula'=binormal(invnormal(`F_eps_d'),invnormal(` F_u'),`thet
    > a')
    11. qui gen double `deriv_cop'=normal((1-`theta'^2)^(-1/2)*(invnormal(`F_u')-`th
    > eta'*invnormal(`F_eps_c')))
    12. qui replace `lnf'=log(`F_eps_d'+`F_u'-`copula') if $ML_y1==0
    13. qui replace `lnf'=log((1-`deriv_cop')*`f_eps') if $ML_y1>0
    14. end

    .
    . ml model lf doublehurdle_gaussian1 (worked=`consvars') (everworked=`partvars') (lnsigma
    > ,nocons) (aththeta,nocons)
    note: region4 omitted because of collinearity
    note: maritals5 omitted because of collinearity
    note: region4 omitted because of collinearity
    note: maritals5 omitted because of collinearity

    . capture noisily ml maximize

    initial: log likelihood = -<inf> (could not be evaluated)
    feasible: log likelihood = -4534.5439
    rescale: log likelihood = -3456.0122
    rescale eq: log likelihood = -3425.1135
    could not calculate numerical derivatives -- discontinuous region with missing values
    encountered

    . matrix A=(e(b),0,0)
    last estimates not found
    r(301);

    end of do-file

    r(301);

  • #2
    Difficult to say without knowing the likelihood. It could be a problem with the formulas of your likelihood (you compute `copula' in the first program but do not use it). It is typical when working with copulas. Some variables of your model could have missing values. I would show the vector and gradient during the optimization to identify the problem. You could also try to summarize some of the components of the likelihood so you could spot any mistakes there, for example if the number of observations is right.

    Comment


    • #3
      Thank you Mr. Christophe.
      I checked my variables and there is no missing data. When I implement these codes to another sample data set from Wooldridge 2010, they work perfectly. However, I come across the same problem when working with my data. How should I summarize the components of Likelihood? How should I know if the number of observations is right?

      Comment


      • #4
        like summarize `F_eps' and check whether it reports the expected number of observations. Try with other temporary variables. Stata tells you that the likelihood has missing values, there could be a problem when you try to compute one these locals resulting in missing values. It's worth checking whether it is the case.

        I suggested an issue with missing values because you are estimating a hurdle model. But that does not seem to be the problem.

        It could also be that the dataset you are using do not conform to the model you are estimating, whereas Wooldridge's dataset does. Finally there could be numerical issues which show up with your dataset but not with that from Wooldridge. Which dataset from Wooldridge are you using?

        Comment


        • #5
          Thank you. I used SMOKE.DTA from Wooldridge's data sets. I will be doing all your suggestions one by one. I'll update you with my progress.

          Comment


          • #6
            What is numerical issues in this case? Can you please give an example? How to know that my data doesn't conform to the model? ( When all the codes work with SMOKE.DTA, is that means that my codes has no problem but my data has problem) What are temporary variables?

            Comment


            • #7
              I solved this problem. The problem was because of my data not the codes.

              Comment

              Working...
              X