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]
Re: st: Multivariate GMM using Mata's "optimize" command: conformability error.
From
Daniel Hubbard <[email protected]>
To
[email protected]
Subject
Re: st: Multivariate GMM using Mata's "optimize" command: conformability error.
Date
Thu, 12 Dec 2013 00:45:41 -0500
Hi Austin,
Thank you for your help. Adding pi and invV as externals does remove
the conformability error. It now returns a different error (430,
"could not calculate numerical derivatives -- discontinuous region
with missing values encountered"), but this is likely a problem with
the data and not with the program, so I'll have to go hunting for the
cause of that myself.
I'll also try learning more about the gmm command.
Thanks again!
Daniel Hubbard
On Wed, Dec 11, 2013 at 12:57 PM, Austin Nichols
<[email protected]> wrote:
> Daniel Hubbard <[email protected]>:
>
> Why not simply use -gmm- now that it is available?
> But perhaps Mata cannot see your variables? Try e.g.:
>
> mata: ;
> pi = st_matrix("pi_out");
> V = st_matrix("V_out");
> invV = invsym(V);
> x = J(1,12,0);
> void i_crit(todo,x,crit,g,H) {;
> external pi ;
> external invV;
> beta = x[1..4];
> gamma = x[5..8];
> lambda = x[9..12];
> m = pi - (vec(beta :* I(4)))' - (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);
>
> On Tue, Dec 10, 2013 at 5:23 PM, Daniel Hubbard <[email protected]> wrote:
>> 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/
*
* 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/