Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

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

From   Christoph Jäckel <>
Subject   st: How to incorporate several dependent variables to the moment evaluating function in gmm?
Date   Mon, 26 Nov 2012 15:30:58 +0100

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:

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


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

*   For searches and help try:

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