Announcement

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

  • #16
    Dear Robert, I see, and thanks.

    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

    Comment


    • #17
      Dear Colleagues,
      I am estimating earnings with selection from a multinomial logit model with three alternatives in a first stage. In the second stage I regress earnings introducing IMR calculated in the first stage. It is quite close to Prof. Huang's post: https://www.statalist.org/forums/for...w-to-bootstrap
      In my case, I am not working in a panel scenario. My case is a cross-section. I tried to replicate Prof. Samuel's code but it doesn't work:
      My first quiestion is why shouldn't I just regress my second stage just as Prof. Huang did initially:
      // second stage
      reg ca ca0 imr1 if err == 1, robust
      reg ca ca0 imr2 if err == 2, robust
      reg ca ca0 imr3 if err == 3, robust

      And second, in case any of you could have a look at my replication, I wounder if you could check if I am wrong and where...

      Replication code:
      Code:
         
       save d1, replace  
           
       cap program drop _all  
       scalar drop _all  
       macro drop _all  
           
       /* Convert CODE to PROGRAM  */  
       program define twostep, rclass  
           tempfile mlogit  
           // first stage  
           statsby _b, saving(`mlogit', replace): mlogit choice_mnl edad1 edad2 d_mujer d_educacion_compacta2 ///  
               d_educacion_compacta3 d_castellano d_departamentos41 d_departamentos42 d_departamentos43 d_ingNoLaboral d_vivpropia d_ayudaFliarGob ///  
               d_TrabajoInformal d_contratoIndefinido d_hogarPobre, baseoutcome(3)  
            
           merge m:1 using `mlogit'  
           sort id  
           
           gen del1 = _eq1_b_edad1*edad1 + _eq1_b_edad2*edad2 + _eq1_b_d_mujer*d_mujer + _eq1_b_d_educacion_compacta2*d_educacion_compacta2 + ///  
               _eq1_b_d_educacion_compacta3*d_educacion_compacta3 + _eq1_b_d_castellano*d_castellano + _eq1_b_d_departamentos41*d_departamentos41 + ///  
               _eq1_b_d_departamentos42*d_departamentos42 + _eq1_b_d_departamentos43*d_departamentos43 + _eq1_b_d_ingNoLaboral*d_ingNoLaboral + ///  
               _eq1_b_d_vivpropia*d_vivpropia + _eq1_b_d_ayudaFliarGob*d_ayudaFliarGob + _eq1_b_d_TrabajoInformal*d_TrabajoInformal + ///  
               _eq1_b_d_contratoIndefinido*d_contratoIndefinido + _eq1_b_d_hogarPobre*d_hogarPobre + _eq1_b_cons  
           gen del2 = _eq2_b_edad1*edad1 + _eq2_b_edad2*edad2 + _eq2_b_d_mujer*d_mujer + _eq2_b_d_educacion_compacta2*d_educacion_compacta2 + ///  
               _eq2_b_d_educacion_compacta3*d_educacion_compacta3 + _eq2_b_d_castellano*d_castellano + _eq2_b_d_departamentos41*d_departamentos41 + ///  
               _eq2_b_d_departamentos42*d_departamentos42 + _eq2_b_d_departamentos43*d_departamentos43 + _eq2_b_d_ingNoLaboral*d_ingNoLaboral + ///  
               _eq2_b_d_vivpropia*d_vivpropia + _eq2_b_d_ayudaFliarGob*d_ayudaFliarGob + _eq2_b_d_TrabajoInformal*d_TrabajoInformal + ///  
               _eq2_b_d_contratoIndefinido*d_contratoIndefinido + _eq2_b_d_hogarPobre*d_hogarPobre + _eq2_b_cons  
           
           gen F1 = exp(del1)/(1+exp(del2)+exp(del1))  
           gen F2 = exp(del2)/(1+exp(del2)+exp(del1))  
           gen F3 = 1/(1+exp(del1)+exp(del2))  
             
           gen J1 = -invnormal(F1)  
           gen J2 = -invnormal(F2)  
           gen J3 = -invnormal(F3)  
           
           gen imr1 = -normalden(J1)/F1  
           gen imr2 = -normalden(J2)/F2  
           gen imr3 = -normalden(J3)/F3  
           // second stage  
           tempfile t1  
           save `t1'  
           forvalues i = 1/3 {  
               use `t1', clear  
               regress ln_w edad1 imr`i' if choice_mnl==`i'  
               local xedad1 =  _b[edad1]  
               return scalar edad1_`i' = `xedad1'  
               local ximr =  _b[imr`i']  
               return scalar imr_`i' = `ximr'  
               local xcons =  _b[_cons]  
               return scalar cons_`i' = `xcons'  
               /* Now must drop variables created in the program  
                  or generate will fail silently in replicates  
                  because variables already exist */  
               }  
            drop _merge del2 del3 F1 F2 F3 J1 J2 J3 imr1 imr2 imr3  
       end  
           
       use d1, clear  
       /* Check Program twostep */  
       twostep  
       return list    
           
       /* Bootstrap program twostep */  
       bootstrap edad1_1 = r(edad1_1) imr1_1 = r(imr1_1)  ///  
                 edad1_2 = r(edad1_2) imr1_2 = r(imr1_2)  ///  
                 edad1_3 = r(edad1_3) imr1_3 = r(imr1_3), ///  
                 nodrop reps(10): twostep  
           
       estat bootstrap, all  
       log close"
      Many thanks indeed.
      Kind regards,
      Ernesto

      Comment

      Working...
      X