Announcement

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

  • gmm moment evaluator program - adding a generated variable that is not used changes the results, but why?

    I illustrate my question using an example from the documentation of
    Code:
     help gmm
    :

    Code:
    webuse auto
    
    cap program drop gmm_ivreg
    program gmm_ivreg
        version 15.1
        syntax varlist [if] , at(name) rhs(varlist) depvar(varlist)
    
        tempvar m
        quietly gen double `m' = 0 `if'
        local i 1
        foreach var of varlist `rhs' {
            quietly replace `m' = `m' + `var'*`at'[1,`i'] `if'
            local `++i'
        }
        quietly replace `m' = `m' + `at'[1,`i'] `if'    // constant
        quietly replace `varlist' = `depvar' - `m' `if'
    end
    
    gmm gmm_ivreg, nequations(1) nparameters(3) instruments(gear_ratio length headroom) depvar(mpg) rhs(gear_ratio turn)
    The estimate for b1 is .0034983.

    Now I add a single line of code (I create a variable called junk) to the moment-evaluator program:

    Code:
    cap program drop gmm_ivreg
    program gmm_ivreg
        version 15.1
        syntax varlist [if] , at(name) rhs(varlist) depvar(varlist)
    
        tempvar m
        quietly gen double `m' = 0 `if'
        local i 1
        foreach var of varlist `rhs' {
            quietly replace `m' = `m' + `var'*`at'[1,`i'] `if'
            local `++i'
        }
        quietly replace `m' = `m' + `at'[1,`i'] `if'    // constant
        quietly replace `varlist' = `depvar' - `m' `if'
    
         cap drop junk
         gen junk = turn
    end
    
    gmm gmm_ivreg, nequations(1) nparameters(3) instruments(gear_ratio length headroom) depvar(mpg) rhs(gear_ratio turn)
    Although I thought the additional line should have no effect on the estimation results, the results do change in fact. The estimate for b1 now is .0258675.

    Why?

  • #2
    I can confirm your experience. Furthermore, replacing
    Code:
    gen junk = turn
    with
    Code:
    gen junk = weight
    produces an estimate for b1 of .2822437. And replacing that with
    Code:
    gen junk = 1
    produces the original estimate. This is also the case when 1 is replaced by 3 or by -3, but not when it is replaced by 0, which produces
    Code:
    Step 1
    initial values not feasible
    r(1400);
    This was all done with Stata 16.1.

    If nobody else can shed light on this (I know nothing specific about how gmm works) I suggest you ask Stata Technical Support to have a look at this topic.

    Comment


    • #3
      Dear Falko and William,

      Thanks for reporting this issue. We are looking into it. On the meantime, Falko, please modify your code to generate the variables as tempvars. In your example:

      Code:
      cap program drop gmm_ivreg
      program gmm_ivreg
          version 15.1
          syntax varlist [if] , at(name) rhs(varlist) depvar(varlist)
      
          tempvar m junk
          quietly gen double `m' = 0 `if'
          local i 1
          foreach var of varlist `rhs' {
              quietly replace `m' = `m' + `var'*`at'[1,`i'] `if'
              local `++i'
          }
          quietly replace `m' = `m' + `at'[1,`i'] `if'    // constant
          quietly replace `varlist' = `depvar' - `m' `if'
          gen `junk' = turn
      end

      Comment


      • #4
        Dear William and Enrique,

        thanks a lot for having looked at the issue. I am looking forward to further news about it.

        Best

        Falko

        Comment


        • #5
          Dear Falko,

          This issue has been fixed and will be available in a future update.

          Comment

          Working...
          X