Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: GMM error (bug in Stata?)


From   John Antonakis <[email protected]>
To   [email protected]
Subject   Re: st: GMM error (bug in Stata?)
Date   Mon, 31 Oct 2011 21:59:03 +0100

Hi:

To close this tread:

Mea Culpa. There must have been a very small and very silly mistake in my code; there is no bug in gmm.

I reran the code (that Brian sent me back) and it works fine. What I think I had done is that when copying and pasting my code between my e-mail program and Stata there was an inadvertent hard return I had added between two lines (I was doing it to verify that I had not made a mistake in the code, and then I added a mistake in there in the process!) .

Here's the nice code Brian sent me (that is nicely organized and clear to see):

gmm                                      ///
    (eq1: y - {b1}*x_style1 - {b2}*x_style2- {b3}*x_style3        ///
            - {b4}*x_style4 - {b5}*x_style5- {b6}*x_style6         ///
            - {b7}*x_style7 - {b8}*x_style8- {b9}*x_style9         ///
            - {b10}*x_style10 - {b11}*x_style11 - {b12}*x_style12    ///
            - {b13}*x_style13- {b0})                 ///
    (eq2: y - {c1}*x_style1 - {c2}*x_style2- {c3}*x_style3         ///
            - {c4}*x_style4 - {c5}*x_style5- {c6}*x_style6        ///
            - {c7}*x_style7 - {c8}*x_style8- {c9}*x_style9        ///
            - {c10}*x_style10 - {c11}*x_style11 - {c12}*x_style12    ///
            - {c13}*x_style13- {c0}),                 ///
    instruments(eq1: x_fe1 x_fe2 x_fe3 x_fe4 x_fe5 x_fe6 x_fe7     ///
             x_fe8 x_fe9 x_fe10 x_fe11 x_fe12 x_fe13 )     ///
    instruments(eq2: x_clus1 x_clus2 x_clus3 x_clus4 x_clus5     ///
             x_clus6 x_clus7 x_clus8 x_clus9 x_clus10    ///
             x_clus11 x_clus12 x_clus13)             ///
    twostep winitial(unadjusted, indep) vce(cluster lead_n)

Now, I figured out how to reproduce my dumb mistake. I must have run my code, with hard return before declaring Eq2, like this:

gmm                                      ///
    (eq1: y - {b1}*x_style1 - {b2}*x_style2- {b3}*x_style3        ///
            - {b4}*x_style4 - {b5}*x_style5- {b6}*x_style6         ///
            - {b7}*x_style7 - {b8}*x_style8- {b9}*x_style9         ///
            - {b10}*x_style10 - {b11}*x_style11 - {b12}*x_style12    ///
            - {b13}*x_style13- {b0})                 ///

    (eq2: y - {c1}*x_style1 - {c2}*x_style2- {c3}*x_style3         ///
            - {c4}*x_style4 - {c5}*x_style5- {c6}*x_style6        ///
            - {c7}*x_style7 - {c8}*x_style8- {c9}*x_style9        ///
            - {c10}*x_style10 - {c11}*x_style11 - {c12}*x_style12    ///
            - {c13}*x_style13- {c0}),                 ///
    instruments(eq1: x_fe1 x_fe2 x_fe3 x_fe4 x_fe5 x_fe6 x_fe7     ///
             x_fe8 x_fe9 x_fe10 x_fe11 x_fe12 x_fe13 )     ///
    instruments(eq2: x_clus1 x_clus2 x_clus3 x_clus4 x_clus5     ///
             x_clus6 x_clus7 x_clus8 x_clus9 x_clus10    ///
             x_clus11 x_clus12 x_clus13)             ///
    twostep winitial(unadjusted, indep) vce(cluster lead_n)

Stata conks out (and this is not Stata's fault, of course):

. gmm /// > (eq1: y - {b1}*x_style1 - {b2}*x_style2- {b3}*x_style3 /// > - {b4}*x_style4 - {b5}*x_style5- {b6}*x_style6 /// > - {b7}*x_style7 - {b8}*x_style8- {b9}*x_style9 /// > - {b10}*x_style10 - {b11}*x_style11 - {b12}*x_style12 /// > - {b13}*x_style13- {b0}) ///
>
Model not identified.  There are more parameters than instruments.
r(481);

I am so sorry I did not notice this before; this is such an idiotic mistake and I am embarrassed by it.

I apologize for the time it took me to figure this out and for the bandwidth it took; in particularly, thank you to Brian for ensuring that all's fine with Stata.

Best regards,
John.

__________________________________________

Prof. John Antonakis
Faculty of Business and Economics
Department of Organizational Behavior
University of Lausanne
Internef #618
CH-1015 Lausanne-Dorigny
Switzerland
Tel ++41 (0)21 692-3438
Fax ++41 (0)21 692-3305
http://www.hec.unil.ch/people/jantonakis

Associate Editor
The Leadership Quarterly
__________________________________________


On 31.10.2011 16:34, Brian P. Poi wrote:
> John Antonakis wrote:
>> Hi:
>>
>> I am trying to estimate "stacked" models using -gmm-. When I estimate the two models separately, things work fine (see code on the bottom of my e-mail). However, when I run the models jointly, with the following code...........
>>
>> gmm  ///
>
> <...>
>
>>
>> ...........I get an error, which is a "strange" error, because the model is just identified (i.e,. I have an equal number of instruments as endogenous regressors):
>>
>> . gmm  ///
>>> (eq1: y - {b1}*x_style1 - {b2}*x_style2- {b3}*x_style3- {b4}*x_style4-
>> ///
>>>  {b5}*x_style5- {b6}*x_style6 - {b7}*x_style7- {b8}*x_style8-
>> {b9}*x_style9- ///
>>>  {b10}*x_style10- {b11}*x_style11- {b12}*x_style12- {b13}*x_style13-
>> {b0}) ///
>> Model not identified.  There are more parameters than instruments.
>> r(481);
>>
>> Here's the code for the separate gmm models:
>>
>
> <...>
>
>> Any ideas as to what the problem is?
>
> John sent his dataset in to Stata tech support so that I could try to replicate the problem here. However, when I ran his code on my Linux machine using both Stata 11 IC and Stata 12 MP as well as on a colleague's Windows machine with Stata 12 MP, I was unable to replicate the error message. In all cases, the results from the stacked model matched the results from the individual models. The complete log file is at the end of this message.
>
> The error message John received is a bit surprising in this context. That error is detected by simply counting the number of parameters and comparing it to the number of rows in the initial weight matrix, which is based on the instruments you specify. In John's model with 28 parameters, as long as there are a total of 28 instruments, that test should have passed.
>
> I will follow up with John privately, and I'll report back to the list if we figure out why he received that error message.
>
>
> Brian P. Poi
> Senior Economist
> StataCorp LP
>
>
> -------------------------------------------------------------------------------
>       name: <unnamed>
>        log:  /home/bpp/tmp/gmm/st12.log
>   log type:  text
>  opened on:  31 Oct 2011, 09:45:46
>
> . do it
>
> . clear all
>
> . use gmm
>
> .
> . gmm /// >> (eq1: y - {b1}*x_style1 - {b2}*x_style2- {b3}*x_style3 /// >> - {b4}*x_style4 - {b5}*x_style5- {b6}*x_style6 /// >> - {b7}*x_style7 - {b8}*x_style8- {b9}*x_style9 /// >> - {b10}*x_style10 - {b11}*x_style11 - {b12}*x_style12 /// >> - {b13}*x_style13- {b0}) /// >> (eq2: y - {c1}*x_style1 - {c2}*x_style2- {c3}*x_style3 /// >> - {c4}*x_style4 - {c5}*x_style5- {c6}*x_style6 /// >> - {c7}*x_style7 - {c8}*x_style8- {c9}*x_style9 /// >> - {c10}*x_style10 - {c11}*x_style11 - {c12}*x_style12 /// >> - {c13}*x_style13- {c0}), /// >> instruments(eq1: x_fe1 x_fe2 x_fe3 x_fe4 x_fe5 x_fe6 x_fe7 /// >> x_fe8 x_fe9 x_fe10 x_fe11 x_fe12 x_fe13 ) /// >> instruments(eq2: x_clus1 x_clus2 x_clus3 x_clus4 x_clus5 /// >> x_clus6 x_clus7 x_clus8 x_clus9 x_clus10 /// >> x_clus11 x_clus12 x_clus13) ///
>>         twostep winitial(unadjusted, indep) vce(cluster lead_n)
>
> Step 1
> Iteration 0:   GMM criterion Q(b) =  25.229434
> Iteration 1:   GMM criterion Q(b) =  5.867e-27
> Iteration 2:   GMM criterion Q(b) =  7.849e-32
>
> Step 2
> Iteration 0:   GMM criterion Q(b) =  4.824e-32
> Iteration 1:   GMM criterion Q(b) =  4.460e-32
>
> GMM estimation
>
> Number of parameters =  28
> Number of moments    =  28
> Initial weight matrix: Unadjusted Number of obs = 3344
> GMM weight matrix:     Cluster (lead_n)
>
> (Std. Err. adjusted for 418 clusters in lead_n) > ------------------------------------------------------------------------------
>              |               Robust
> | Coef. Std. Err. z P>|z| [95% Conf. Interval] > -------------+---------------------------------------------------------------- > /b1 | 1.049204 .0549893 19.08 0.000 .9414266 1.156981 > /b2 | 1.078344 .0586466 18.39 0.000 .9633983 1.193289 > /b3 | .9043237 .0616768 14.66 0.000 .7834394 1.025208 > /b4 | 1.04687 .0528909 19.79 0.000 .9432057 1.150534 > /b5 | 1.043876 .0569363 18.33 0.000 .9322833 1.155469 > /b6 | 1.01851 .0592967 17.18 0.000 .9022906 1.134729 > /b7 | .9258437 .0602654 15.36 0.000 .8077256 1.043962 > /b8 | .9485584 .0553715 17.13 0.000 .8400322 1.057085 > /b9 | 1.066044 .0601146 17.73 0.000 .9482216 1.183867 > /b10 | 1.075929 .0577217 18.64 0.000 .9627967 1.189062 > /b11 | 1.017601 .0614807 16.55 0.000 .8971007 1.138101 > /b12 | -.9610472 .0526738 -18.25 0.000 -1.064286 -.8578085 > /b13 | -.9627249 .0589321 -16.34 0.000 -1.07823 -.8472202 > /b0 | -.1096011 .0587362 -1.87 0.062 -.2247219 .0055198 > /c1 | .9598146 .0517448 18.55 0.000 .8583967 1.061232 > /c2 | .9256337 .0535588 17.28 0.000 .8206605 1.030607 > /c3 | .8305105 .0582733 14.25 0.000 .7162969 .9447241 > /c4 | .956631 .0482825 19.81 0.000 .8619991 1.051263 > /c5 | .9736638 .053159 18.32 0.000 .8694742 1.077853 > /c6 | .9493385 .0541098 17.54 0.000 .8432853 1.055392 > /c7 | .8518398 .0555893 15.32 0.000 .7428867 .9607929 > /c8 | .8813955 .051279 17.19 0.000 .7808906 .9819004 > /c9 | .9793823 .0518981 18.87 0.000 .877664 1.081101 > /c10 | .9923967 .0533734 18.59 0.000 .8877868 1.097007 > /c11 | .8911549 .0555809 16.03 0.000 .7822183 1.000092 > /c12 | -.865805 .0502334 -17.24 0.000 -.9642607 -.7673493 > /c13 | -.8909156 .0537489 -16.58 0.000 -.9962615 -.7855697 > /c0 | -.1046114 .0564682 -1.85 0.064 -.2152871 .0060643 > ------------------------------------------------------------------------------ > Instruments for equation 1: x_fe1 x_fe2 x_fe3 x_fe4 x_fe5 x_fe6 x_fe7 x_fe8
>     x_fe9 x_fe10 x_fe11 x_fe12 x_fe13 _cons
> Instruments for equation 2: x_clus1 x_clus2 x_clus3 x_clus4 x_clus5 x_clus6
>     x_clus7 x_clus8 x_clus9 x_clus10 x_clus11 x_clus12 x_clus13 _cons
>
> .
> .
> .
> .
> . gmm /// >> (eq1: y - {b1}*x_style1 - {b2}*x_style2- {b3}*x_style3 /// >> - {b4}*x_style4 - {b5}*x_style5- {b6}*x_style6 /// >> - {b7}*x_style7 - {b8}*x_style8 - {b9}*x_style9 /// >> - {b10}*x_style10 - {b11}*x_style11- {b12}*x_style12 /// >> - {b13}*x_style13 - {b0}), /// >> instruments(eq1: x_fe1 x_fe2 x_fe3 x_fe4 x_fe5 x_fe6 x_fe7 /// >> x_fe8 x_fe9 x_fe10 x_fe11 x_fe12 x_fe13 ) ///
>>         twostep winitial(unadjusted, indep) vce(cluster lead_n)
>
> Step 1
> Iteration 0:   GMM criterion Q(b) =  13.184222
> Iteration 1:   GMM criterion Q(b) =  1.492e-26
> Iteration 2:   GMM criterion Q(b) =  4.349e-32
>
> Step 2
> Iteration 0:   GMM criterion Q(b) =  4.278e-33
> Iteration 1:   GMM criterion Q(b) =  4.278e-33  (backed up)
>
> GMM estimation
>
> Number of parameters =  14
> Number of moments    =  14
> Initial weight matrix: Unadjusted Number of obs = 3344
> GMM weight matrix:     Cluster (lead_n)
>
> (Std. Err. adjusted for 418 clusters in lead_n) > ------------------------------------------------------------------------------
>              |               Robust
> | Coef. Std. Err. z P>|z| [95% Conf. Interval] > -------------+---------------------------------------------------------------- > /b1 | 1.049204 .0549893 19.08 0.000 .9414266 1.156981 > /b2 | 1.078344 .0586466 18.39 0.000 .9633983 1.193289 > /b3 | .9043237 .0616768 14.66 0.000 .7834394 1.025208 > /b4 | 1.04687 .0528909 19.79 0.000 .9432057 1.150534 > /b5 | 1.043876 .0569363 18.33 0.000 .9322833 1.155469 > /b6 | 1.01851 .0592967 17.18 0.000 .9022906 1.134729 > /b7 | .9258437 .0602654 15.36 0.000 .8077256 1.043962 > /b8 | .9485584 .0553715 17.13 0.000 .8400322 1.057085 > /b9 | 1.066044 .0601146 17.73 0.000 .9482216 1.183867 > /b10 | 1.075929 .0577217 18.64 0.000 .9627967 1.189062 > /b11 | 1.017601 .0614807 16.55 0.000 .8971007 1.138101 > /b12 | -.9610472 .0526738 -18.25 0.000 -1.064286 -.8578085 > /b13 | -.9627249 .0589321 -16.34 0.000 -1.07823 -.8472202 > /b0 | -.1096011 .0587362 -1.87 0.062 -.2247219 .0055198 > ------------------------------------------------------------------------------ > Instruments for equation 1: x_fe1 x_fe2 x_fe3 x_fe4 x_fe5 x_fe6 x_fe7 x_fe8
>     x_fe9 x_fe10 x_fe11 x_fe12 x_fe13 _cons
>
> .
> .
> . gmm /// >> (eq1: y - {c1}*x_style1 - {c2}*x_style2- {c3}*x_style3 /// >> - {c4}*x_style4 - {c5}*x_style5- {c6}*x_style6 /// >> - {c7}*x_style7 - {c8}*x_style8- {c9}*x_style9 /// >> - {c10}*x_style10 - {c11}*x_style11 - {c12}*x_style12 /// >> - {c13}*x_style13 - {c0}), /// >> instruments(eq1: x_clus1 x_clus2 x_clus3 x_clus4 x_clus5 /// >> x_clus6 x_clus7 x_clus8 x_clus9 x_clus10 /// >> x_clus11 x_clus12 x_clus13) ///
>>         twostep winitial(unadjusted, indep) vce(cluster lead_n)
>
> Step 1
> Iteration 0:   GMM criterion Q(b) =  12.045213
> Iteration 1:   GMM criterion Q(b) =  2.039e-26
> Iteration 2:   GMM criterion Q(b) =  3.079e-32
>
> Step 2
> Iteration 0:   GMM criterion Q(b) =  3.482e-33
> Iteration 1:   GMM criterion Q(b) =  2.055e-33
>
> GMM estimation
>
> Number of parameters =  14
> Number of moments    =  14
> Initial weight matrix: Unadjusted Number of obs = 3344
> GMM weight matrix:     Cluster (lead_n)
>
> (Std. Err. adjusted for 418 clusters in lead_n) > ------------------------------------------------------------------------------
>              |               Robust
> | Coef. Std. Err. z P>|z| [95% Conf. Interval] > -------------+---------------------------------------------------------------- > /c1 | .9598146 .0517448 18.55 0.000 .8583967 1.061232 > /c2 | .9256337 .0535588 17.28 0.000 .8206605 1.030607 > /c3 | .8305105 .0582733 14.25 0.000 .7162969 .9447241 > /c4 | .956631 .0482825 19.81 0.000 .8619991 1.051263 > /c5 | .9736638 .053159 18.32 0.000 .8694742 1.077853 > /c6 | .9493385 .0541098 17.54 0.000 .8432853 1.055392 > /c7 | .8518398 .0555893 15.32 0.000 .7428867 .9607929 > /c8 | .8813955 .051279 17.19 0.000 .7808906 .9819004 > /c9 | .9793823 .0518981 18.87 0.000 .877664 1.081101 > /c10 | .9923967 .0533734 18.59 0.000 .8877868 1.097007 > /c11 | .8911549 .0555809 16.03 0.000 .7822183 1.000092 > /c12 | -.865805 .0502334 -17.24 0.000 -.9642607 -.7673493 > /c13 | -.8909156 .0537489 -16.58 0.000 -.9962615 -.7855697 > /c0 | -.1046114 .0564682 -1.85 0.064 -.2152871 .0060643 > ------------------------------------------------------------------------------ > Instruments for equation 1: x_clus1 x_clus2 x_clus3 x_clus4 x_clus5 x_clus6
>     x_clus7 x_clus8 x_clus9 x_clus10 x_clus11 x_clus12 x_clus13 _cons
>
> .
> .
> end of do-file
>
> . log c
>       name: <unnamed>
>        log:  /home/bpp/tmp/gmm/st12.log
>   log type:  text
>  closed on:  31 Oct 2011, 09:53:14
> -------------------------------------------------------------------------------
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index