Statalist


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

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


From   Stas Kolenikov <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Cluster-robust estimate of the VCE, GMM, Mata
Date   Fri, 17 Jul 2009 10:59:04 -0500

Without going into any of the substantive details -- you could get the
sandwich VCE with

optimize_result_V_robust( S )

and in all likelihood you could get cluster corrected standard errors
along the lines of

// some prep work in creating empty score_vars
st_view( score_vars=., ., tokens("`score_vars'"))
score_vars[,] = optimize_result_scores(S)
end
// of Mata
_robust `score_vars' , cluster( cluster )

As a side note, I personally find clustering on age to be a relatively
strange idea, to tell you the truth. If you think there's dependence
on age, you could just as well use it as a covariate in your model
somewhere. Clustering is a problem when your sample was collected
using clusters of units sampled together; imposing clustering based on
exogenous variables is infrequently sensible, I think.

On Thu, Jul 16, 2009 at 6:53 AM, Rodolphe
Desbordes<rodolphe.desbordes@strath.ac.uk> wrote:
> 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/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index