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

From |
László Sándor <sandorl@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Fri, 2 Oct 2009 14:08:16 -0400 |

Please never mind, I found a typical embarrassing typo in my variable names. I appreciate your help. Laszlo 2009/10/2 László Sándor <sandorl@gmail.com> > > Thank you, Brian. > > I had network access to Stata 11, thus I did not access the manuals, > but have consulted them since. The examples are not fundamentally > different from those I found in David Drukker's presentation or the > help file. > > I am sorry I sent you the version I desperately experimented with but > surely had an error, which you spotted. I also tried -gmm- without any > variable after the moment evaluator function call: > "gmm msm, equations(demand) parameters(cons weight hp ac cons) > instruments( weight hp ac cons cons2 hp2 weight2 ac2, noconstant)" > > I got the same error as before: > varlist required > varlist required > error calling msm at initial values > varlist required > (error occurred while loading msm.ado) > r(100); > > Without draining your resources and precious time, could you try once > more to spot the point where either my mata function, or my moment > evaluator function in the ado-file, or the main GMM call requests > something I am not providing? I really tried to follow the logic and > syntax of the examples. > > "msm.ado" is: > program msm > version 11 > syntax varlist [if], at(name) > quietly { > cap drop deltastar > cap drop sigma > cap drop xi > gen deltastar = 0 > gen sigma = 0 > gen xi = 0 > matrix beta = `at' > mata: > st_matrix(beta,"beta") > fingerscrossed(beta) > end > replace `varlist' = xi `if' > } > end > > The mata function "fingerscrossed.mo" comes from the code: > mata: > void function 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 weight hp ac cons") > st_view(d,.,"deltastar") > st_view(sig,.,"sig") > st_view(s,.,"share") > st_view(p,.,"price") > st_view(xi,.,"xi") > 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 > end > > Thank you in advance, your help is greatly appreciated! > > Laszlo > > On Thu, Oct 1, 2009 at 3:21 PM, Brian P. Poi <bpoi@stata.com> wrote: > > > > On Thu, 1 Oct 2009, László Sándor wrote: > > > >> 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): http://www.stata.com/meeting/dcconf09/abstracts.html > >> (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.) > >> > > > > Laszlo might want to look at the reference manual entry for -gmm-, which is available in PDF format to all Stata 11 users. In particular, the technical note after example 9 shows how to write a moment evaluator program that allows you to specify your own dependent and independent variables. Examples 10 and 11 also show how to do this, as does the program on page 616. > > > > Laszlo wrote: > >> > >> ... varlist in his command either: "gmm xtfe ," (But mentioned a varlist > >> in the syntax -- still, it worked for him.) > > > > In your moment evaluator program, near the top there will be a line like this: > > > > syntax varlist if, at(name) ... > > > > That `varlist' does not contain the names of your dependent variables. Rather, it contains the names of temporary variables that you are to fill in with the sample residuals for each of the moment equations. The number of variables in `varlist' equals the number you specify in the nequations() option or the number of names you specify in the equations() option. The ... in my -syntax- statement is the key to passing other information to your moment evaluator program. In the examples in the Reference manual, the moment evaluator program accepts additional options mylhs() and myrhs(), which are how you pass the name of the dependent and independent variables to the program when you call -gmm-. > > > > Laszlo called -gmm- using the command > > > > . gmm msm moment, nequations(1) parameters(cons hp weight ac) > > instruments(cons hp weight ac cons2 hp2 weight2 ac2, noconstant) > > > > When you use the moment-evaluator program with -gmm-, you do not specify a variable name after the name of the moment-evaluator program, so the command should be something more like > > > > . gmm msm, nequations(1) parameters(cons hp weight ac) > > instruments(cons hp weight ac cons2 hp2 weight2 ac2, noconstant) > > > > perhaps with additional options depending on what options you decide to pass onto your moment-evaluator program. > > > > None of the examples in the -gmm- reference manual entry discuss using Mata to compute the sample residuals in the moment-evaluator program, but there is nothing in principle that stops you from doing so. We will consider adding an example in the help file for -gmm- that shows how to do this. > > > > -- Brian Poi > > -- bpoi@stata.com * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: question: getting GMM working with a moment-evaluator program***From:*László Sándor <sandorl@gmail.com>

**Re: st: question: getting GMM working with a moment-evaluator program***From:*"Brian P. Poi" <bpoi@stata.com>

**Re: st: question: getting GMM working with a moment-evaluator program***From:*László Sándor <sandorl@gmail.com>

- Prev by Date:
**RE: st: RE: Keeping trailing zeros when formatting a decimal** - Next by Date:
**Re: st: weird margins** - Previous by thread:
**Re: st: question: getting GMM working with a moment-evaluator program** - Next by thread:
**Re: st: mi estimate and xtmixed: reporting of groups** - Index(es):

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