Announcement

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

  • Help with stata manual

    Dear STATA-listers

    I am struggling to understand how to implement the example at pag.32 of the STATA MANUAL (link below). Shortly put, I want to run a GMM estimator with a poisson distribution and considering one regressor as endogenous. This is exactly the procedure described at pag 32 which I am not able to replicate even for the example provided. If I understood correctly, as a first step i should run the program described at pag 33 and then I could run the example provided at pag. 28. However, I obtain the following error message:

    error calling gmm_poi at initial values
    ‘mu’ invalid name

    I guess need to change somehow the code at pag.32 but I have no idea how. Can somebody help me out? This is only the example !

    Thanks a lot for your help!!



    http://www.stata.com/manuals13/rgmm.pdf
    Last edited by Mario Scintille; 03 Feb 2016, 11:35.

  • #2
    Mario:
    I can replicate the example in Stata 14:
    Code:
    . program gmm_poiend
      1.
    . version 13
      2.
    . syntax varlist if, at(name)
      3.
    . quietly {
      4.
    . tempvar mu
      5.
    . matrix score double `mu' = `at' `if', eq(#1)
      6.
    . replace `mu' = exp(`mu')
      7.
    . local mylhs : coleq `at'
      8.
    . local mylhs : word 1 of `mylhs'
      9.
    . replace `varlist' = `mylhs'/`mu' - L.`mylhs'/L.`mu' `if'
     10.
    . }
     11.
    . end
    
    . use http://www.stata-press.com/data/r13/poisson2
    
    . gmm gmm_poiend, nequations(1) vce(cluster id) onestep parameters(y:x1 y:x2 y:x3) instruments(x1 x2 L2.x3, noconstant)
    note: 500 missing values returned for equation 1 at initial values
    
    Step 1
    Iteration 0:   GMM criterion Q(b) =  43.799922 
    Iteration 1:   GMM criterion Q(b) =  .06998898 
    Iteration 2:   GMM criterion Q(b) =  .04165161 
    Iteration 3:   GMM criterion Q(b) =  .03573502 
    Iteration 4:   GMM criterion Q(b) =  .00001981 
    Iteration 5:   GMM criterion Q(b) =  3.168e-12 
    Iteration 6:   GMM criterion Q(b) =  1.529e-23 
    
    note: model is exactly identified
    
    GMM estimation
    
    Number of parameters =   3
    Number of moments    =   3
    Initial weight matrix: Unadjusted                 Number of obs   =      3,266
    
                                       (Std. Err. adjusted for 500 clusters in id)
    ------------------------------------------------------------------------------
                 |               Robust
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              x1 |   1.857766   .2631454     7.06   0.000      1.34201    2.373521
              x2 |  -2.865858   .2151529   -13.32   0.000     -3.28755   -2.444167
              x3 |   4.961867   14.91462     0.33   0.739    -24.27025    34.19399
    ------------------------------------------------------------------------------
    Instruments for equation 1: x1 x2 L2.x3
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo,

      thanks a lot for your quick answer. I am quite puzzled. I am running stata 13.1 so I think the code should run given that it has been apparently designed for STATA 13 (is this the meaning of the second line of the code "Version 13", right?). Do you simply copy paste the code from the manual in a do file and then run the "use" and "gmm" commands? Do you obtain the same results as in the manual ?

      Thanks a lot. I am sorry for the many questions but i am very puzzled at this point

      Kind regards

      Comment


      • #4
        If you copy and paste the commands below in the Stata command window, it should work.
        Code:
        program gmm_poiend
        version 13
        syntax varlist if, at(name)
        quietly {
        tempvar mu
        matrix score double `mu' = `at' `if', eq(#1)
        replace `mu' = exp(`mu')
        local mylhs : coleq `at'
        local mylhs : word 1 of `mylhs'
        replace `varlist' = `mylhs'/`mu' - L.`mylhs'/L.`mu' `if'
        }
        end
        use http://www.stata-press.com/data/r13/poisson2
        gmm gmm_poiend, nequations(1) vce(cluster id) onestep parameters(y:x1 y:x2 y:x3) instruments(x1 x2 L2.x3, noconstant)
        -version 13- tells Stata to set the command interpreter to version 13

        Comment


        • #5
          ‘mu’ invalid name
          macros need to be referenced with the left single quote (located at the upper left on most keyboards), the macro name, and a right single quote (located under the " on the right side of most keyboards).

          When I cut and pasted the code from the manual I had to first change all the single quote marks - both left and right.

          Change this
          Code:
          matrix score double ‘mu’ = ‘at’ ‘if’, eq(#1)
          to this:
          Code:
          matrix score double `mu' = `at' `if', eq(#1)

          Comment


          • #6
            Dear Eric and Scott, thanks a lot. The problem was exactly the one you spotted!

            May i ask two more questions?
            1) In order to use this estimator on my model, the only thing i need to do is to replace "y" with my dependent variable and "x1", "x2" ".." with my explanatory variables (which are six and not three). Also I need to specify my id in the vce option. correct?
            2) would it be possible to insert time dummies in the model?

            Once more, thanks for your help.

            Kind regards

            Comment


            • #7
              dear all, any idea? Thanks a lot,
              mario

              Comment


              • #8
                See section 17 in the FAQ.

                Comment

                Working...
                X