Statalist


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

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


From   Rodolphe Desbordes <[email protected]>
To   "'[email protected]'" <[email protected]>
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 http://cameron.econ.ucdavis.edu/racd/trcount2009.do 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
mata
  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
    _makesymmetric(H)
   }
  st_view(y=., ., "`y'")
  st_view(X=., ., tokens("`xlist'"))
  st_view(Z=., ., tokens("`zlist'"))

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

  S = optimize_init()
  optimize_init_which(S,"min")
  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))
  optimize_init_technique(S,"nr")
  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)
  st_matrix("b",b)
  st_matrix("Vb",Vb)
end
"

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,

Rodolphe


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



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