Оценщик программы GMM не любит мою временную переменную - PullRequest
0 голосов
/ 10 марта 2020

Насколько я могу судить, две программы в приведенном ниже коде идентичны. В первой программе я просто назначаю параметр скаляру. Во второй программе я храню этот скаляр для каждого наблюдения во временной переменной.

Математически, это должно быть то же самое, но вторая программа выдает «числовые производные являются приблизительными» и «встречается плоская или прерывистая область».

Почему при втором подходе нельзя правильно вычислить производные?

clear
set obs 10000
set seed 42

gen x = runiform() * 10
gen eps = rnormal()

gen y = 2 + .3 * x + eps

capture program drop testScalar
program testScalar
    syntax varlist [if], at(name)

    scalar b0 = `at'[1,1]
    scalar b1 = `at'[1,2]

    replace `varlist' = y - b0 - b1* x
end

capture program drop testTempvar
program testTempvar
    syntax varlist [if], at(name)

    tempvar tmp

    scalar b0 = `at'[1,1]
    scalar b1 = `at'[1,2]

    gen `tmp' = b1

    replace `varlist' = y - b0 - `tmp'* x

end

gmm testScalar, nequations(1) nparameters(2) instr(x) winitial(identity) onestep
gmm testTempvar, nequations(1) nparameters(2) instr(x) winitial(identity) onestep

Вывод:

. gmm testScalar, nequations(1) nparameters(2) instr(x) winitial(identity) onestep
(10,000 real changes made)

Step 1
Iteration 0:   GMM criterion Q(b) =  417.93313  
Iteration 1:   GMM criterion Q(b) =  1.690e-23  
Iteration 2:   GMM criterion Q(b) =  3.568e-30  

note: model is exactly identified

GMM estimation 

Number of parameters =   2
Number of moments    =   2
Initial weight matrix: Identity                   Number of obs   =     10,000

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         /b1 |   2.022865   .0200156   101.06   0.000     1.983635    2.062095
         /b2 |   .2981147    .003465    86.04   0.000     .2913235    .3049059
------------------------------------------------------------------------------
Instruments for equation 1: x _cons

. gmm testTempvar, nequations(1) nparameters(2) instr(x) winitial(identity) onestep
(10,000 real changes made)

Step 1
Iteration 0:   GMM criterion Q(b) =  417.93313  
numerical derivatives are approximate
flat or discontinuous region encountered
Iteration 1:   GMM criterion Q(b) =  8.073e-17  
numerical derivatives are approximate
flat or discontinuous region encountered
Iteration 2:   GMM criterion Q(b) =  8.073e-17  (backed up)

note: model is exactly identified

GMM estimation 

Number of parameters =   2
Number of moments    =   2
Initial weight matrix: Identity                   Number of obs   =     10,000

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         /b1 |   2.022865   .0201346   100.47   0.000     1.983402    2.062328
         /b2 |   .2981147   .0034933    85.34   0.000      .291268    .3049613
------------------------------------------------------------------------------
Instruments for equation 1: x _cons

. 

1 Ответ

2 голосов
/ 10 марта 2020

В программе testTempvar вам нужно сгенерировать временную переменную tmp типа double:

generate double `tmp' = b1

Другими словами, это проблема точности.

...