Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Multivariate GMM using Mata's "optimize" command: conformability error.


From   Daniel Hubbard <danieldh@umich.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Multivariate GMM using Mata's "optimize" command: conformability error.
Date   Tue, 10 Dec 2013 17:23:30 -0500

Hi everyone,

I am trying to use GMM to run a test of the validity of fixed effects
using "optimize" in Mata (in Stata 12.1). The program is based on the
one found in Austin Nichols' presentation found at
http://repec.org/snasug08/nichols_gmm.pdf ; the test is based on
section 2.2 of George Jakubson's 1990 paper "Estimating the Union Wage
Effect", found at http://www.jstor.org/stable/10.2307/2297947 (a
Google Scholar search does not turn up a free version of the paper -
sorry!).

In the first stage (omitted here, though I can add it if it would be
helpful), I estimate a 16-element row vector called "pi_out" and a
16x16 matrix called "V_out", which I import in the second stage. My
second-stage code is as follows:

/*** SECOND STAGE ***/
mata: ;
    pi = st_matrix("pi_out");
    V = st_matrix("V_out");
    invV = invsym(V);
    I = I(4);
    x = J(1,12,0);
    void i_crit (todo,x,crit,g,H) {;
        beta = x[1..4];
        gamma = x[5..8];
        lambda = x[9..12];
        m = pi - (vec(beta :* I))' - (gamma # lambda);
        crit = (m*invV*m');
    };
    init=J(1,12,0);
    S=optimize_init();
    optimize_init_evaluator(S, &i_crit());
    optimize_init_which(S, "min");
    optimize_init_evaluatortype(S, "d0");
    optimize_init_params(S, init);
    p=optimize(S);
end;
/*** END SECOND STAGE ***/

When I get to the last line of this (running "optimize"), I receive
"i_crit():  3200  conformability error" at the top of the traceback
log. I tried to replicate the i_crit function by hand (running each of
the five lines inside it individually), and it worked perfectly; it
created a 16-element vector for "m" and a scalar for "crit", as
expected.

These aren't the correct values of "m" and "crit", because they aren't
optimized (all the Greek letter variables are still zero), but
everything adds and multiplies together just as it is supposed to, so
the source of the conformability error isn't clear to me. Is there
something particular to "optimize" that is incorrectly specified in my
code? I'm still in the process of learning Mata, which I am largely
doing by trial and error.

Thank you for your help; let me know if anything is unclear. The full
traceback is posted below, if it is helpful.

Daniel Hubbard
Education Policy Initiative
University of Michigan, Gerald Ford School of Public Policy

:     p=optimize(S);
                i_crit():  3200  conformability error
      opt__calluser0_d():     -  function returned error
      opt__d0_calluser():     -  function returned error
    deriv__call1user_d():     -  function returned error
 _deriv__compute_value():     -  function returned error
                _deriv():     -  function returned error
       opt__eval_nr_d0():     -  function returned error
             opt__eval():     -  function returned error
opt__looputil_iter0_common():
    -  function returned error
opt__looputil_iter0_nr():     -  function returned error
          opt__loop_nr():     -  function returned error
              optimize():     -  function returned error
                 <istmt>:     -  function returned error
(0 lines skipped)
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index