Announcement

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

  • Defining GMM program using optimize and generating wild bootstrap standard errors

    Hello Statalist Members,

    I am trying to manually optimize a GMM function (simple production function) and I have all my results, now I have to generate the wild bootstrap standard errors using a particular method described below. The trouble here is that I am new to using matrices in Stata and I cannot get around with a way where I have to repeat the same procedure say 100 times to generate my standard errors and store them in one place and then calculate confidence intervals from them to draw the diagrams. Any help regarding the loop to repeat the process, save the results and then using them for the required purpose will be really appreciated. I am attaching the procedure of the bootstrap and my code below;

    regress y k z1k1 z2k1 l z1l1 z2l1 m z1m1 z2m1 i.year [pweight = weight]
    mat b = e(b)

    local k = b[1,1]
    local kz1 = b[1,2]
    local kz2 = b[1,3]
    local l = b[1,4]
    local lz1 = b[1,5]
    local lz2 = b[1,6]
    local m = b[1,7]
    local mz1 = b[1,8]
    local mz2 = b[1,9]
    local cons_ols_cd = b[1,49]

    mata:
    void GMM_DLW(todo,betas,crit,g,H)
    {
    PHI=st_data(.,("phi_wt"))
    PHI_LAG=st_data(.,("Phi_wt"))
    Z=st_data(.,("const_wt","k_wt","kZ_wt","kZ2_wt", "L_wt","LZ_wt", "LZ2_wt", "M_wt", "MZ_wt", "MZ2_wt"))
    X=st_data(.,("const_wt","k_wt", "z1k1","z2k1", "l_wt", "z1l1", "z2l1", "m_wt", "z1m1", "z2m1"))
    X_lag=st_data(.,("const_wt", "K_wt", "KZ_wt", "KZ2_wt", "L_wt", "LZ_wt", "LZ2_wt", "M_wt", "MZ_wt", "MZ2_wt"))
    Y=st_data(.,("y_wt"))
    C=st_data(.,("const_wt"))

    OMEGA=PHI-X*betas'
    OMEGA_lag=PHI_LAG-X_lag*betas'
    OMEGA_lag_pol=(C,OMEGA_lag)
    g_b = invsym(OMEGA_lag_pol'OMEGA_lag_pol)*OMEGA_lag_pol' OMEGA
    XI=OMEGA-OMEGA_lag_pol*g_b
    crit=(Z'XI)'(Z'XI)
    }
    void DLW()
    {
    S=optimize_init()
    optimize_init_evaluator(S, &GMM_DLW())
    optimize_init_evaluatortype(S,"d0")
    optimize_init_technique(S, "nm")
    optimize_init_nmsimplexdeltas(S, 0.1)
    optimize_init_which(S,"min")
    optimize_init_params(S,(`cons_ols_cd',`k',`kz1', `kz2', `l',`lz1', `lz2', `m', `mz1', `mz2'))
    p=optimize(S)
    p
    st_matrix("beta_dlw",p)
    }


    end
    *----------------END MATA PROGRAM----------------*

    cap program drop dlw
    program dlw, rclass
    preserve
    sort $ID $TIME_VAR
    mata DLW()
    end

    dlw

    ************************************************** ***

    And then I have to use the parameters, I store them as locals and generate elasticities in the following manner

    local k = beta_dlw[1,2]
    local kz= beta_dlw[1,3]
    local kz2 = beta_dlw[1,4]

    gen beta_k_z = `k' + `kz'*z + `kz2'*z2

    ************************************************** *****
    For wild bootstrap I have to use the following procedure;

    1. Generate the bootstrap residuals [with some specified procedure in the text]
    2. Construct the bootstrap sample { }
    3. Re-estimate the model using the bootstrap sample (which is the model above)
    4. Repeat steps (1) to (3) for an arbitrary number of times and obtain the bootstrap point-wise standard errors of the estimators

    The bottleneck is only in step 3, where I have to store the results somewhere to be able to use them which I think will be working with some matrices. I can easily follow all other steps just not this part. I will appreciate any help here. Thanks a lot.

Working...
X