Announcement

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

  • Calling MATA optimization routine through a STATA program

    Dear Experts,

    I have written the following codes for GMM estimation. When I call GMM_OPTI(init) outside the STATA program, "struc_esti", using ---mata: GMM_OPTI(st_matrix("init")) --- I get my optimal estimates of "theta."

    But when I call GMM_OPTI(init) through "struc_esti," I get the error message: *: 3200 conformability error. And when I read the elements of X and L_X element by element in CRIT_FN(todo,theta,crit,g,H) and call GMM_OPTI(init) through "struc_esti," struc_esti simply returns the initial values without performing the optimization.

    I need to call GMM_OPTI(init) through "struc_esti" as need to do bootstrapping.

    I wounder what I am missing. Any help would be most welcomed.

    Best
    Amaresh


    #delimit ;
    global omg_endo_poly "C, L1_OMG, L1_OMG:^2, L1_OMG:^3,
    L1_OG, L1_CA, L1_CA:*L1_OG, L1_CA:^2, (L1_CA:^2):*L1_OG,
    L1_OMG:*L1_OG, L1_OMG:*L1_CA, L1_OMG:*L1_CA:*L1_OG, L1_OMG:*(L1_CA:^2), L1_OMG:*(L1_CA:^2):*L1_OG,
    (L1_OMG:^2):*L1_OG, (L1_OMG:^2):*L1_CA, (L1_OMG:^2):*L1_CA:*L1_OG, (L1_OMG:^2):*(L1_CA:^2), (L1_OMG:^2):*(L1_CA:^2):*L1_OG,
    (L1_OMG:^3):*L1_OG, (L1_OMG:^3):*L1_CA, (L1_OMG:^3):*L1_CA:*L1_OG, (L1_OMG:^3):*(L1_CA:^2), (L1_OMG:^3):*(L1_CA:^2):*L1_OG";
    #delimit cr

    *Defining mata routines
    capture mata mata drop CRIT_FN() // For evaluating the criterion function.
    capture mata mata drop GMM_OPTI() // For minimizing the criterions function with respect to the structural parameters.
    * MATA programms ************************************************** *******
    mata:

    void CRIT_FN(todo,theta,crit,g,H)
    {
    stru_vars = st_local("Struc_names")
    st_view(X =., ., tokens(stru_vars) )
    l_stru_vars = st_local("l_Struc_names")
    st_view(L_X =., ., tokens(l_stru_vars) )

    PHI=st_data(.,("phi"))
    L_PHI=st_data(.,("l_phi"))

    L_CA=st_data(.,("l_cua"))
    L_OG=st_data(.,("l_dorg"))

    inst_vars = st_local("inst_vars")
    st_view(Z =., ., tokens(inst_vars) )

    OMG=PHI-(X)*theta'
    L_OMG=L_PHI-(L_X)*theta'
    L_OMG_pol=(${omg_endo_poly})

    beta_prod=invsym(L_OMG_pol'L_OMG_pol)*L_OMG_pol'OM G
    XI=OMG-L1_OMG_pol*beta_prod

    W = invsym(Z'Z)/(rows(Z))
    crit=(Z'XI)'*W*(Z'XI)

    }

    void GMM_OPTI(init)
    {
    S=optimize_init()
    optimize_init_evaluator(S, &CRIT_FN())
    optimize_init_evaluatortype(S, "d0")
    optimize_init_technique(S, "nm")
    optimize_init_nmsimplexdeltas(S, 0.0001)
    optimize_init_which(S, "min")
    optimize_init_params(S, init)
    p=optimize(S)
    p
    st_matrix("theta",p)
    }
    end

    capture program drop struc_esti
    program define struc_esti, rclass

    *GMM_OPTI and CRIT_FN() are two MATA routines for estimating the structural parameters by the method of GMM.
    *GMM_OPTI minimizes the criterion function evaluated in CRIT_FN() with respect to the structural parameters and returns the
    *optimal structural parameters.

    mata: GMM_OPTI(st_matrix("init"))

    return scalar Dummy_OCC =theta[1,1]
    return scalar Dummy_OCC =theta[1,2]
    return scalar Dummy_REG =theta[1,3]

    return scalar Labor_NON =theta[1,4]
    return scalar Labor_OCC =theta[1,5]
    return scalar Labor_REG =theta[1,6]

    return scalar Capit_NON =theta[1,7]
    return scalar Capit_OCC =theta[1,8]
    return scalar Capit_REG =theta[1,9]

    return scalar Harjumaa_NON=theta[1,10]
    return scalar Harjumaa_OCC=theta[1,11]
    return scalar Harjumaa_REG=theta[1,12]

    end
    Last edited by Amaresh Tiwari; 14 Nov 2022, 07:10.
Working...
X