Announcement

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

  • Invalid name

    Hi! I tried to replicate an example on the tutorials. https://www.stata.com/manuals13/rgmm.pdf (Example 12).
    The code is
    Click image for larger version

Name:	1.png
Views:	2
Size:	31.6 KB
ID:	1557973


    I copied this program and then run the code below.

    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)

    but it showed that ‘mu’ invalid name.

    Can anyone tell me why this happened? Thanks.

  • #2
    Dapeng:
    it works for me with Stata 16 (please note that I have only replaced 13 with 16 as far as -version- is concerned; no missing observations, though):
    Code:
    . program gmm_poiend
      1.
    . version 16
      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/r16/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) =  61.832288 
    Iteration 1:   GMM criterion Q(b) =  .03402584 
    Iteration 2:   GMM criterion Q(b) =  .01101288 
    Iteration 3:   GMM criterion Q(b) =  6.339e-06 
    Iteration 4:   GMM criterion Q(b) =  1.620e-12 
    Iteration 5:   GMM criterion Q(b) =  1.312e-25 
    
    note: model is exactly identified
    
    GMM estimation
    
    Number of parameters =   3
    Number of moments    =   3
    Initial weight matrix: Unadjusted                 Number of obs   =      3,766
    
                                       (Std. Err. adjusted for 500 clusters in id)
    ------------------------------------------------------------------------------
                 |               Robust
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              x1 |     1.8141   .2688318     6.75   0.000       1.2872    2.341001
              x2 |  -2.982671   .1086666   -27.45   0.000    -3.195653   -2.769688
              x3 |   4.126518   6.369334     0.65   0.517    -8.357147    16.61018
    ------------------------------------------------------------------------------
    Instruments for equation 1: x1 x2 L2.x3
    
    .
    Caveat emptor: I've not delved into model (correct) specification, I've simply given it a try and check possible Stata gaspings along the way.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      See also #3 in https://www.statalist.org/forums/for...s-in-intervals by William Lisowski .

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Thanks, Nick! It is useful!

        Comment


        • #5
          Originally posted by Carlo Lazzaro View Post
          Dapeng:
          it works for me with Stata 16 (please note that I have only replaced 13 with 16 as far as -version- is concerned; no missing observations, though):
          Code:
          . program gmm_poiend
          1.
          . version 16
          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/r16/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) = 61.832288
          Iteration 1: GMM criterion Q(b) = .03402584
          Iteration 2: GMM criterion Q(b) = .01101288
          Iteration 3: GMM criterion Q(b) = 6.339e-06
          Iteration 4: GMM criterion Q(b) = 1.620e-12
          Iteration 5: GMM criterion Q(b) = 1.312e-25
          
          note: model is exactly identified
          
          GMM estimation
          
          Number of parameters = 3
          Number of moments = 3
          Initial weight matrix: Unadjusted Number of obs = 3,766
          
          (Std. Err. adjusted for 500 clusters in id)
          ------------------------------------------------------------------------------
          | Robust
          | Coef. Std. Err. z P>|z| [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          x1 | 1.8141 .2688318 6.75 0.000 1.2872 2.341001
          x2 | -2.982671 .1086666 -27.45 0.000 -3.195653 -2.769688
          x3 | 4.126518 6.369334 0.65 0.517 -8.357147 16.61018
          ------------------------------------------------------------------------------
          Instruments for equation 1: x1 x2 L2.x3
          
          .
          Caveat emptor: I've not delved into model (correct) specification, I've simply given it a try and check possible Stata gaspings along the way.
          Thanks, Carlo!

          Comment

          Working...
          X