Announcement

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

  • GMM estimation with category variable return error message "could not evaluate equation 1 r(498)"

    Hello everyone,

    I am using GMM estimation to fit a logit model of Y on endogenous variable X with Z as instrument, conditional on boy1 age age2 birthage1 mom_eduyr dad_eduyr rural mom_eth dad_eth birthyr dad_birthy dprovcn2-dprovcn30.
    It is a cross section data that including around 50000 households. My stata version is Stata/IC 13.1.
    Example of my data
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float boy1 byte age float(age2 birthage1 mom_eduyr dad_eduyr rural mom_eth dad_eth)
    0 13  9 26  14  16 0 1 1
    0 10  7 25  12   9 0 1 1
    1 10  9 25   9   9 0 1 1
    0 13 10 25   9   9 1 1 1
    1  7  2 31   6   9 1 0 0
    0  7  3 23   9   9 1 0 0
    The regressors including 12 variables(some of them are dummies) and 29 state dummies dprovcn2-dprovcn30,

    Previously, I included dummy variables without prefix i. and I was able to obtain GMM estimators. See below, here I am not including all the output.
    Code:
    global xlist boy1 age age2 birthage1 mom_eduyr dad_eduyr rural mom_eth dad_eth dprovcn2-dprovcn30
    
    . 
    . global xb "{X}*X + {boy1}*boy1 + {age}*age + {age_2}*age_2 + {birthage1}*birthage1 + {mom_eduyr}*mom_ed> uyr + {dad_eduyr}*dad_eduyr + {rural}*rural + {mom_eth}*mom_eth + {dad_eth}*dad_eth  + {dprovcn2}*dprovcn2+{dprovcn3}*dprovcn3+{dprovcn4}*dprovcn4+{dprovcn5}*dprovcn5+{dprovcn6}*dprovcn6+{dprovcn7}*dprovcn7 +{dprovcn8}*dprovcn8+{dprovcn9}*dprovcn9+{dprovcn10}*dprovcn10+{dprovcn11}*dprovcn11+{dprovcn12}*dprovcn12+{dprovcn13}*dprovcn13+{dprovcn13}*dprovcn13+{dprovcn13}*dprovcn13+{dprovcn14}*dprovcn14+{dprovcn14} *dprovcn14+{dprovcn15}*dprovcn15+{dprovcn16}*dprovcn16+{dprovcn17}*dprovcn17+{dprovcn18}*dprovcn18+{dprovcn19}*dprovcn19+{dprovcn20}*dprovcn20+{dprovcn21}*dprovcn21+{dprovcn22}*dprovcn22+{dprovcn23}*dprovcn23+{dprovcn24}*dprovcn24+{dprovcn25}*dprovcn25+{dprovcn26}*dprovcn26+{dprovcn27}*dprovcn27+{dprovcn28}*dprovcn28+{dprovcn29}*dprovcn29+{dprovcn30}*dprovcn30 + {cons}"
    
    . global Ey "exp($xb)/(1+exp($xb))" 
    
    gmm (Y-$Ey), instruments(Z $xlist)  vce(robust)  
    
    Step 1
    Iteration 0:   GMM criterion Q(b) =   .15719873
    However, when I tries to specify dummy variables with prefix i., stata returned error message "could not evaluate equation 1 r(498)".
    Previously state dummies were generated based on variable provcn, here I use i.provcn for ease.

    Code:
    global xlist_new i.boy1 age c.age#c.age birthage1 mom_eduyr dad_eduyr rural i.mom_eth i.dad_eth i.provcn
    
    . global xb "{X}*X + {boy1}*1.boy1 + {age}*age + {age_2}*c.age#c.age + {birthage1}*birthage1 + {mom_eduyr }*mom_eduyr + {dad_eduyr}*dad_eduyr + {rural}*rural + {mom_eth}*i.mom_eth + {dad_eth}*i.dad_eth  + {provcn}*i.provcn + {cons}"
    
    . 
    . global Ey "exp($xb)/(1+exp($xb))" 
    
    . 
    . gmm (Y-$Ey), instruments(Z $xlist)  vce(robust)  
    could not evaluate equation 1
    r(498);
    I do not understand what went wrong. I prefer to specify categorical nature of the data so that I can calculate marginal effects afterwards, but it seems GMM command cannot cope with this issue. Anybody has suggestions?

    Also, does anybody has advice on computing marginal effects after GMM estimation?

    Many thanks
    Yi

  • #2
    Does anybody has suggestions? Any comment is welcomed

    Comment


    • #3
      I cannot use your data above because you do not include all your variables. Nonetheless, consider the following linear model estimated using GMM

      Code:
      sysuse auto
      regress mpg gear_ratio turn i.rep78
      It makes no sense for me to write the model as below

      Code:
      gmm (mpg - {b1}*gear_ratio - {b2}*turn - {b3}*i.rep78 -{b0}), instruments(gear_ratio turn i.rep78)
      For i.rep78, I need to estimate k-1 parameters where k represents the total number of levels of rep78. In fact, if I do so, I will get the same error message as you do

      Code:
      . gmm (mpg - {b1}*gear_ratio - {b2}*turn - {b3}*i.rep78 -{b0}), instruments(gear_ratio turn i.rep78)
      could not evaluate equation 1
      r(498);
      There are 2 remedies

      1) Write out the equation in full (not efficient if you have too many levels of a categorical variable)

      Code:
      gmm (mpg - {b1}*gear_ratio - {b2}*turn - {b3}*2.rep78- {b4}*3.rep78 - ...   -{b0}), instruments(gear_ratio turn 2.rep78 ... 5.rep78)
      2) To include factor variables, state the model as follows

      Code:
      gmm (mpg - {xb:gear_ratio turn i.rep78} - {b0}),instruments(gear_ratio turn i.rep78)

      Comment


      • #4
        Dear Andrew

        Many thanks for your kind reply. I was working on another project and delayed for checking Statalist. My apologies.

        The first remedy won't work in my case since I do have many levels of categorical variables.

        The second remedy does not seem to work. I have no idea why factor variables are not allowed in the gmm regression.
        Code:
        gmm (mpg - {xb:gear_ratio turn i.rep78} - {b0}),instruments(gear_ratio turn i.rep78)
        factor variables not allowed
        r(101);
        I would also like to know if you have any suggestion on calculating margin effects after gmm estimation.

        Many thanks
        Yi

        Comment


        • #5
          The second remedy does not seem to work. I have no idea why factor variables are not allowed in the gmm regression.
          What version of Stata are you running? Version 14 allows you to use factor variables, so try getting hold of it.

          Code:
          . sysuse auto
          (1978 Automobile Data)
          
          . gmm (mpg - {xb:gear_ratio turn i.rep78} - {b0}),instruments(gear_ratio turn i.rep78)
          
          Step 1
          Iteration 0:   GMM criterion Q(b) =  474.36438  
          Iteration 1:   GMM criterion Q(b) =  4.170e-21  
          Iteration 2:   GMM criterion Q(b) =  8.283e-30  
          
          Step 2
          Iteration 0:   GMM criterion Q(b) =  1.571e-30  
          Iteration 1:   GMM criterion Q(b) =  9.468e-31  
          
          note: model is exactly identified
          
          GMM estimation
          
          Number of parameters =   7
          Number of moments    =   7
          Initial weight matrix: Unadjusted                 Number of obs   =         69
          GMM weight matrix:     Robust
          
          ------------------------------------------------------------------------------
                       |               Robust
                       |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
            gear_ratio |   3.740388   1.368303     2.73   0.006     1.058562    6.422213
                  turn |  -.6588993   .1223039    -5.39   0.000    -.8986106    -.419188
                       |
                 rep78 |
                    2  |   .5080954   2.280294     0.22   0.824      -3.9612     4.97739
                    3  |  -1.395567   2.161799    -0.65   0.519    -5.632616    2.841482
                    4  |  -1.994642   2.198133    -0.91   0.364    -6.302904    2.313619
                    5  |   1.335085   3.089089     0.43   0.666    -4.719419    7.389589
          -------------+----------------------------------------------------------------
                   /b0 |   37.14905   8.593296     4.32   0.000     20.30649     53.9916
          ------------------------------------------------------------------------------
          Instruments for equation 1: gear_ratio turn 1b.rep78 2.rep78 3.rep78 4.rep78 5.rep78 _cons
          The first remedy won't work in my case since I do have many levels of categorical variables.
          Generating dummies with the tab, gen option, here is a trick to shorten your code. It takes no longer than using factor variables.

          Code:
          . tab rep78, gen(rep78)
          
               Repair |
          Record 1978 |      Freq.     Percent        Cum.
          ------------+-----------------------------------
                    1 |          2        2.90        2.90
                    2 |          8       11.59       14.49
                    3 |         30       43.48       57.97
                    4 |         18       26.09       84.06
                    5 |         11       15.94      100.00
          ------------+-----------------------------------
                Total |         69      100.00
          
          . gmm (mpg - {b1}*gear_ratio - {b2}*turn - {xb:rep782-rep785}-{b0}), instruments(gear_ratio turn rep782-rep785)
          
          Step 1
          Iteration 0:   GMM criterion Q(b) =  474.36438  
          Iteration 1:   GMM criterion Q(b) =  4.170e-21  
          Iteration 2:   GMM criterion Q(b) =  7.052e-30  
          
          Step 2
          Iteration 0:   GMM criterion Q(b) =  1.198e-30  
          Iteration 1:   GMM criterion Q(b) =  1.198e-30  (backed up)
          
          note: model is exactly identified
          
          GMM estimation
          
          Number of parameters =   7
          Number of moments    =   7
          Initial weight matrix: Unadjusted                 Number of obs   =         69
          GMM weight matrix:     Robust
          
          ------------------------------------------------------------------------------
                       |               Robust
                       |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          b1           |
                 _cons |   3.740388   1.368303     2.73   0.006     1.058562    6.422213
          -------------+----------------------------------------------------------------
          b2           |
                 _cons |  -.6588993   .1223039    -5.39   0.000    -.8986106    -.419188
          -------------+----------------------------------------------------------------
          xb           |
                rep782 |   .5080954   2.280294     0.22   0.824      -3.9612     4.97739
                rep783 |  -1.395567   2.161799    -0.65   0.519    -5.632616    2.841482
                rep784 |  -1.994642   2.198133    -0.91   0.364    -6.302904    2.313619
                rep785 |   1.335085   3.089089     0.43   0.666    -4.719419    7.389589
          -------------+----------------------------------------------------------------
                   /b0 |   37.14905   8.593296     4.32   0.000     20.30649     53.9916
          ------------------------------------------------------------------------------
          Instruments for equation 1: gear_ratio turn rep782 rep783 rep784 rep785 _cons


          Last edited by Andrew Musau; 19 Aug 2016, 14:52.

          Comment


          • #6
            Dear Andrew

            Yes, Version 14 did cure all the hiccups. The first remedy won't suit my case anyway since I will need marginal effects afterwards.

            Many thanks for taking your time through this.

            Best
            Yi

            Comment

            Working...
            X