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]

Re: st: How to incorporate several dependent variables to the moment evaluating function in gmm?


From   "Brian P. Poi" <[email protected]>
To   [email protected]
Subject   Re: st: How to incorporate several dependent variables to the moment evaluating function in gmm?
Date   Mon, 26 Nov 2012 09:48:27 -0600

On 11/26/2012 08:30 AM, Christoph Jäckel wrote:
Hello Stata experts,

I'm just learning Stata and I'm struggling with the following
problem. I want to map a time-series regression with several dependent
variables into a GMM.

Let's make a small example. I have two dependent variables y1 and y2
and one explaining factor x1. Then I get the following moments that
should all be zero:

E[(y1 - a1 - b1 * x1)]
E[(y2 - a2 - b2 * x1)]
E[(y1 - a1 - b1 * x1)x1]
E[(y2 - a2 - b2 * x1)x1]

where a1, a2, b1, and b2 are the parameters to estimate. I found this
link on the list that deals with several equations in a GMM:
http://www.stata.com/statalist/archive/2011-06/msg00363.html

However, as far as I can see, the dependent variable is not changed.
What I actually want: I want to pass a list of vectors to the moment
evaluating function and create the relevant moments for each vector of
that list. Those vectors are the dependent variables.

I think it's clearer when I show you what I tried so far.

_______________
sysuse auto, clear

program mygmm

         version 12

         syntax varlist [if] , at(name) mylhs(varlist)

         local eq1 : word 1 of `mylhs'
         local eq2 : word 2 of `mylhs'
*Approach 1: Breaks with error "varlist not allowed"
*        quietly replace `eq1' = `eq1' - `at'[1,1] - `at'[1,3]*turn
*        quietly replace `eq2' = `eq2' - `at'[1,2] - `at'[1,4]*turn

*Approach 2: Breaks with error "varlist not allowed"
local j=1
     foreach lhs of varlist `mylhs' {
     replace `mylhs' = `mylhs' - `at'[1,j] - `at'[1,2 + j]*turn
     j = j + 1
}

end

gmm mygmm, nequations(4) nparameters(4) mylhs(mpg headroom)
instruments(turn) winitial(identity)
_______________

Here, I took the example from the link above, but I am now trying to
have two different dependent variables, namely mpg and headroom. I
tried two approaches: the first is pretty similar to the one given in
the link, the second just loops to the mylhs list. Both don't work,
and I don't quite understand why. I hope I passed the arguments
correctly, but to be fair, I'm not sure if I do. I don't quite get the
syntax of the example in the link, to start with. What should a moment
evaluating function do exactly? What should it return? In the examples
I found, it always sets  `varlist' to the moments that should be zero,
which makes sense to me. For instance, here
(http://www.stata.com/features/generalized-method-of-moments/gmm.pdf)
on p. 27 the last line is

replace `varlist' = `mylhs' - `mu'*`ybar'/`mubar' `if'

I think I get this: `varlist' is set to an expression that depends on
the parameters and then a search for the parameters is started that
should sets `varlist' to zero (since Moments=Parameters).  My problem
is that
my `varlist' is not just one vector as in the examples I found, but a
list of factors.

Note that the above example is simple enough to just give the formulas:

_______________
#delimit ;
gmm (mpg      - ({alpha1=0} + {beta1=0}*turn))
(headroom - ({alpha2=0} + {beta2=0}*turn))
, inst (turn) onestep winitial(identity) ;
#delimit cr
_______________

However, I want to run more complicated models and therefore I need to
know how to write moment evaluating functions correctly. Any help is
greatly appreciated.

Christoph

Christoph,

You are almost there.  The `varlist' in the evaluator function is the list of variables into which you are to place the values of the residual functions.  That's different from the list of variables you specify in your mylhs() option.  For simplicity, let me swap the order of two of your moment equations:

E[(y1 - a1 - b1 * x1)]
E[(y1 - a1 - b1 * x1)x1]
E[(y2 - a2 - b2 * x1)]
E[(y2 - a2 - b2 * x1)x1]

You have two residual functions: (y1 - a1 - b1 * x1) and (y2 - a2 - b2 * x2), each interacted with a constant term and x1, yielding a total of four moment conditions.  When you specify nequations(2) (not 4 as you tried), `varlist' will have two elements where you are to place the two residual functions.  Here's working version of your program:


sysuse auto, clear

program mygmm

        version 12

        syntax varlist [if] , at(name) mylhs(varlist)

        local eq1 : word 1 of `varlist'
        local eq2 : word 2 of `varlist'

        local y1 : word 1 of `mylhs'
        local y2 : word 2 of `mylhs'

        quietly replace `eq1' = `y1' - `at'[1,1] - `at'[1,3]*turn
        quietly replace `eq2' = `y2' - `at'[1,2] - `at'[1,4]*turn


end

gmm mygmm, nequations(2) nparameters(4) mylhs(mpg headroom)	///
    instruments(turn) winitial(identity) onestep


Because we specified instruments(turn) without any suboptions, both turn and a constant will be used as instruments for each of the residual functions.

If you use your code

#delimit ;
gmm (mpg      - ({alpha1=0} + {beta1=0}*turn))
(headroom - ({alpha2=0} + {beta2=0}*turn))
, inst (turn) onestep winitial(identity) ;
#delimit cr

you'll get the same results, except that the second and third parameters will be swapped.  In the evaluator program, you take the second element of `at' to be alpha2 and the third element to be beta2.  When -gmm- parses your substitutable expression in the latter case, it will come across beta1 before alpha2, and it builds up the parameter vector in the order in which it finds parameters.

   -- Brian Poi
   -- [email protected]

*
*   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