|  |  | 
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: instrumental variables with ML
I'm estimating a model (AIDS) with ML (thanks to the program from Poi 
concerning the QUAIDS).
I would like to add instrumental variables, but it doesn't work. On the 
other hand, my model without the instrumental variables works.
I'm not an expert in ML command in stata. If someone have an idea. I am 
quite sure that it is easy but I don't succed writing the right code. I 
hope someone can help me.
Thanks.
I 've tried this :
In my general program :
ml model d0  lnl_aids_v_iv   (Y1 = X    p1  T  TR)  (Y2 =   X   p1 p2  
T  TR) (Y3 = X   p1 p2 p3  T  TR)   (X = Z W)
with Z and W the instruments for the variable X that  I suspect to be 
endogeneous.
(The first 3 equations are the same except that some constraints impose 
not to estimate some coefficients)
The ado file "lnl_aids_v_iv" contains the likelihood function of the 
general equation.
program define lnl_aids_v_iv
  version 9.1
  args todo b lnf
  tempvar theta2
  mleval `theta2' = `b', eq(4)   /*I've tried this to catch the 
instrumentation*/
  quietly{
     tempname alpha beta gamma t tr
      local nm1 = $NEQN-1   /*in this case  $NEQN (nb of general 
equations) = 4 but I have only Y1, Y2, Y3 to estimate due to my 
constraints.) */
 
     /* Get the parameters out of b.   */
     quaids_params_iv `b' `alpha' `beta' `gamma' `t' `tr'  /*an ado 
which Breaks up parameter vector into alpha, beta,  gamma, t and tr. The 
constraints recover the coeff for all the 4 general models.*/
         /* Now generate the error terms. */
     forvalues i = 1/$NEQN {
        tempvar lnl_eps`i'        
        gen double `lnl_eps`i'' = Y`i' - `alpha'[1,`i'] -   
`beta'[1,`i']*(`theta2')  - `t'[1,`i'] * T  - `tr'[1,`i'] * TR     
               /*I put "`theta2'" here to take into account the 
instrumentation*/  
        forvalues j = 1/$NEQN {
           replace `lnl_eps`i'' = `lnl_eps`i'' - `gamma'[`i', `j']*p`j'
        }
     }
     local allofem ""
     forvalues i = 1/$NEQN {
        local allofem "`allofem' `lnl_eps`i''"
     }
     /* Form sigma. */
     matrix accum sigma = `allofem', noconstant
     local nobs = r(N)
     matrix sigma = sigma/`nobs'
     /* Chop off last row & column since singular. */
     matrix sigma = sigma[1..`nm1', 1..`nm1']
 
     /* Finally, compute the likelihood function. */
     scalar `lnf' = -1*`nobs'/2*(`nm1'*(1+ln(2*_pi)) + ln(det(sigma)))
  }
 
end
After ml maximize, I have the error "could not calculate numerical 
derivatives flat or discontinuous region encountered". It seems the 
instrumentation is wrong wrong wrong.
Does someone have an idea???
Thanks to have read all this and to tell me if you have any suggestion.
val�rie
--
***********************
Val�rie Orozco
INRA ESR Toulouse -  FRANCE
ESR INRA - BP52627 - 31326 Castanet Tolosan Cedex 
[email protected]
05-61-28-50-97
***********************
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/