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

st: Cluster-robust estimate of the VCE, GMM, Mata

From   Rodolphe Desbordes <>
To   "''" <>
Subject   st: Cluster-robust estimate of the VCE, GMM, Mata
Date   Thu, 16 Jul 2009 12:53:39 +0100

Dear all,

In "Microeconometrics Using Stata" by Colin Cameron and Pravin Trivedi, they explain, pp. 381-383, how to calculate a GMM estimator for a Poisson model with an endogenous regressor. The Mata code can be found here and I reproduce it below:

* Nonlinear 2SLS IV estimator for Poisson

 capture drop cons
capture drop cluster

gen cluster=group(age)

clear mata
generate cons = 1
local y docvis
local xlist private chronic female income cons
local zlist private chronic female income cons
local cluster cluster
  void pgmm(todo, b, y, X, Z, Qb, g, H)
    Xb = X*b'
    mu = exp(Xb)
    h = Z'(y-mu)
    W = cholinv(cross(Z,Z))
    Qb = h'W*h
    if (todo == 0) return
    G = -(mu:*Z)'X
    g = (G'W*h)'
    if (todo == 1) return
    H = G'W*G
  st_view(y=., ., "`y'")
  st_view(X=., ., tokens("`xlist'"))
  st_view(Z=., ., tokens("`zlist'"))

st_view(C=., ., "`cluster'")

  S = optimize_init()
  optimize_init_evaluator(S, &pgmm())
  optimize_init_evaluatortype(S, "d2")
  optimize_init_argument(S, 1, y)
  optimize_init_argument(S, 2, X)
  optimize_init_argument(S, 3, Z)
  optimize_init_params(S, J(1,cols(X),0))
  b = optimize(S)
  // Compute robust estimate of VCE
  Xb = X*b'
  mu = exp(Xb)
  h = Z'(y-mu)
  W = cholinv(cross(Z,Z))
  G = -(mu:*Z)'X
  Shat = ((y-mu):*Z)'((y-mu):*Z)*rows(X)/(rows(X)-cols(X))
  Vb = luinv(G'W*G)*G'W*Shat*W*G*luinv(G'W*G)

I would like to obtain a cluster-robust estimate of the variance-covariance matrix of the estimator (VCE).  Hence, in the Mata code, I tried to replace the expression of Shat by:


V = J(cols(Z), cols(Z), 0)
        for(i=1; i<=colmax(C[.,1]); i++) {
                st_subview(x_j=., select(X, C:==i), ., .)
            st_subview(z_j=., select(Z, C:==i), ., .)
                st_subview(y_j=., select(y, C:==i), ., .)
V = V +(cross(cross(z_j, (y_j- exp(x_j*b')))', cross(z_j, (y_j- exp(x_j* b')))'))

Shat = V*(rows(X))/(rows(X)-cols(X))*(colmax(C[.,1])/(colmax(C[.,1])-1))


However, I do not obtain the same estimates as those given by "poisson docvis private chronic female income, cl(age)". I am not sure what I am doing wrong. Any help would be greatly appreciated.

Best regards,


*   For searches and help try:

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