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

st: question: getting GMM working with a moment-evaluator program

From   László Sándor <>
Subject   st: question: getting GMM working with a moment-evaluator program
Date   Thu, 1 Oct 2009 13:58:29 -0400

Hi all,

I tried to write up a relatively simple GMM estimation, but I needed a
moment-evaluator program to do some simulation for each evaluation
(this basically becomes the method of simulated moments). I tried to
follow of the example of David Drukker, presented in DC this summer
(slides 23-26):
(A similar example is in the -help gmm- file too.)

His GMM evaluator function is tailored for the application, thus uses
some actual variable names, not locals coming from the command. I did
the same (though I also needed to use Mata). Crucially, he had no
varlist in his command either: "gmm xtfe ," (But mentioned a varlist
in the syntax -- still, it worked for him.)

Could you look into what goes wrong here? The error messages did not
help me much. I don't know where is it expecting a varlist, and how I
could provide it. (I admit I am not good with ado files yet.)

The error:

. gmm msm moment, nequations(1) parameters(cons hp weight ac) instruments(cons
> hp weight ac cons2 hp2 weight2 ac2, noconstant)
varlist required
varlist required
error calling msm moment at initial values
varlist required
(error occurred while loading msm.ado)

The mata code defining the function that the evaluator function uses
(this is in the main do-file, but the .mo is saved in the project's
folder, so accessible for the ado-file too, I presume):

    cap drop deltastar sigma xi
    gen deltastar = 0
    gen sigma = 0
    gen xi = 0
void fingerscrossed(real rowvector beta) {
    real scalar ns
    real vector d, sig, s, p, xi, y
    real matrix X, term
    ns = 1000
    st_view(X,.,"cons hp weight ac")
    y  = rnormal(1,ns,35000,45000)
    term = J(rows(d),ns,.)
    while (norm(log(s)-log(sig),2) > 0.01) {
        for (i=1;i<=ns;i++) {
            term[.,i] = exp(d - 1/exp(y[1,i])*p+X*beta')
            term[.,i] = 1/(1+quadsum(term[.,i]))*term[.,i]
        sig = mean(term')
        d[.,.]=d[.,.] + log(s[.,.])-log(sig[.,.])
    xi = d-X*beta'
mata mosave fingerscrossed(), replace

Finally, the moment evaluator function itself (in a separate msm.ado file):

program msm
    version 11
    syntax varlist [if], at(name)
    quietly {
        cap drop deltastar sigma xi
        gen deltastar = 0
        gen sigma = 0
        gen xi = 0
        matrix beta = `at'
            beta = st_matrix("beta")
        replace `varlist' = xi `if'
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index