Announcement

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

  • Heckman with endogenous regressor

    Dear All,

    I would like to estimate the following model:

    Code:
    ivreg2 y x1 x2 (x3=z1 z2 z3 z4), first cluster(id) endog(x3)
    However, I suspect a sample selection problem, so I would like to implemente the Heckman correction. Hence I estimate:

    Code:
    probit dv x1 x2 x3 x5
    predict fitted, xb
    predict pdf=normalden(fitted)
    predict cdf=normal(fitted)
    gen imr=pdf/cdf
    I have been advised not to include the inverse Mill's ratio (imr) directly into my model, because it could produce a bias in the estimation of the standard errors, but to use heckman command in stata. However, as you may notice I have an endogenous regressors in my main equation. Is there any command to perform an iv estimation with heckman correction. I have been searched a little bit around, but I was not able to find anything that can be implemented in Stata. If such a command does not exist, how can I get correct standard errors?

    Thnaks for your help.

    Dario

  • #2
    Dario, you were on the right track. In your code, I assume "dv" is the selection indicator, and "x5" is an exclusive determinant of selection. First, try

    Code:
    probit dv x1 x2 z1 z2 z3 z4 x5
    predict fitted, xb
    gen imr = normalden(fitted)/normal(fitted)
    Note that in the probit estimation, ALL exogenous variables should be included, but not the endogenous x3. Then, run

    Code:
    ivregress 2sls y x1 x2 imr (x3 = z1 z2 z3 z4), ...
    To adjust standard errors, you may enclose all the code (from probit to ivregress) with a program and bootstrap it.

    Comment


    • #3
      Fei Wang thanks for your help. Two issues:

      1) you suggest to include the set of instruments in the probit estimation but not the endogenous variable. Is that right?

      2) could you please elaborate more about the correction of standard errors? What do you mean when you say to enclose all the code with a programm and bootstrap it?

      Thanks again for your hints.

      Comment


      • #4
        Fei Wang I have tried to move on by wrapping the probit and ivreg2 estimation in a program and bootstrap it. I am not sure whether this is what you meant. My code is

        Code:
        probit dv x1 x2 z1 z2 z3 z4 x5
        predict fitted, xb
        gen imr=normalden(fitted)/normal(fitted)
        
        ivreg2 y (x3=z1 z2 z3 z4) imr x1 x2 x5, cluster(id) endog(x3) first
        
        matrix b=e(b)
        matrix list b
        matrix se = vecdiag(e(V))
        forvalues i = 1/5 {
            matrix se[1, `i'] = sqrt(se[1, `i'])
        }
        mat list se
        
        cap program drop myboot
        program define myboot, rclass
            preserve
            bsample
        probit dv x1 x2 z1 z2 z3 z4 x5
        
        tempvar fitted imr
        predict `fitted', xb
        gen `imr' = normalden(fitted) / normal(`fitted')
        
        ivreg2 y (x3=z1 z2 z3 z4) imr x1 x2 x5, cluster(id) endog(x3) first
        
        tempvar b se
        
        matrix `b'=e(b)
        matrix list `b'
        matrix `se' = vecdiag(e(V))
        forvalues i = 1/5 {
            matrix `se'[1, `i'] = sqrt(`se'[1, `i'])
        }
        mat list `se'
        restore
        end
        
        simulate b se, reps(1000) seed(1234): myboot
        
        bstat, stat(b se)
        However I get an error message I cannot solve:

        Code:
        . simulate b se, reps(1000) seed(123): myboot
        type mismatch
        error in expression: b
        r(109)
        I guess this is related to the way I create the matrices of coefficients and standard errors, but I cannot figure out what is going wrong.

        Any suggestion would be highly appreciated.

        Dario
        Last edited by Dario Maimone Ansaldo Patti; 08 Jul 2022, 13:34.

        Comment


        • #5
          Dario, my answers are as below.

          1) you suggest to include the set of instruments in the probit estimation but not the endogenous variable. Is that right?
          Right.

          2) could you please elaborate more about the correction of standard errors? What do you mean when you say to enclose all the code with a programm and bootstrap it?
          I'll show a code example below.

          Code:
          use data, clear
          
          capture program drop myprog
          program define myprog
              capture drop fitted imr
              probit dv x1 x2 z1 z2 z3 z4 x5
              predict fitted, xb
              gen imr = normalden(fitted)/normal(fitted)
              ivregress 2sls y x1 x2 imr (x3 = z1 z2 z3 z4)
          end
          
          bootstrap _b, reps(50): myprog

          Comment


          • #6
            Fei Wang thanks a lot. Indeed my code was full of unecessary elements. Also i understood that i just need to bootstrap the coefficients to get the standard errors as well.

            I was just reading a post on Stata website, where it is suggested to add:

            Code:
            ereturn local cmd="bootstrap"
            to get a better display of the results. But definitely thanks for clarifying my doubts.

            ​​​​​​​Dario

            Comment

            Working...
            X