Skip to content

cluster robust standard errors for Logit, Probit and GMM #863

Open

Description

@josef-pkt

http://www.tandfonline.com/doi/abs/10.1198/jbes.2010.07136#.Ua5-o8rcPIU
Cameron, A. Colin, Jonah B. Gelbach, and Douglas L. Miller. 2011. “Robust Inference With Multiway Clustering.” Journal of Business & Economic Statistics 29 (2): 238–249. doi:10.1198/jbes.2010.07136.

I used this when I implemented cluster robust standard errors, but I didn't look at the second part where they use it for M- and GMM-Estimators.

Activity

  1. josef-pkt commented on Oct 9, 2013

    @josef-pkt
    MemberAuthor

    an implementation for this
    https://github.com/spillz/sci-comp/tree/master/statsmodels-fun

    mailing list
    https://groups.google.com/d/msg/pystatsmodels/Qp3V37AVusY/y6qtiID629EJ

    comment

    I'm trying to connect this to what is already in statsmodels:

    in _cluster_A
    A = numpy.matrix(grad(model.score,B)).transpose()
    should be the same as the Hessian/normalized_cov_params, which we already have in all MLE models.

    _cluster_D: score_cpts = grad(model.loglikeobs,B).transpose()
    The MLE models in discrete have jac which, if I read it correctly, is your
    However, this is not available for all models that have an MLE interpretation

    _cluster_D is the inner sandwich part, which should essentially be the same as S_crosssection (different normalization), and connected in the robust cov in cov_cluster (x should be score for each observation, i.e. jac, I guess)

    So based on Damien's script, if I read this correctly, we can use Hinv S Hinv, (Hinv is inverse Hessian or information) where
    S = J'J outerproduct of jacobian in the heteroscedasticity, or
    S is calculated with any of the robust_covariance functions, cluster, HAC, ...

  2. josef-pkt commented on Dec 9, 2013

    @josef-pkt
    MemberAuthor

    mailing list question about NegativeBinomail
    https://groups.google.com/d/msg/pystatsmodels/yB8z4zjJPJs/edjnA9jzg34J

    The sandwich_covariance currently assume that the score is exog * resid, but the inner calculation only uses the product and not the two components.
    From the source of NegativeBinomial I cannot see right now if resid has the right form, the exog part is multiplicative.
    However, the traceback looks like NegativeBinomial will be more difficult to combine because we have the extra parameter which I assume causes the matrices are not aligned error.

    So maybe we need also the general score version for NegativeBinomial. (I doubt that the covariance for NegativeBinomial is block-diagonal, but I don't know).

  3. josef-pkt commented on Dec 9, 2013

    @josef-pkt
    MemberAuthor

    more from the thread (with fixed typo), see comments in gist script

    the function in sandwich_covariance might not work with pandas datastructures.
    I'm not sure yet why I get some exceptions.

    missing handling is now built into patsy (0.2.x) and also an option
    for the models (missing='drop'), but there is no automatic handling of
    the extra arrays required by the sandwiches, groups, time, ...

    NegativeBinomial doesn't have jac, but it has scoreobs

    Poisson already seems to work for cov_cluster, because it's score has
    the exog * resid structure.
    Logit also has the same structure.

    My last message has the function

    from statsmodels.stats.sandwich_covariance import S_crosssection
    
    
    def cov_cluster_mle(jac, hessian_inv, groups, use_correction=True):
        S = S_crosssection(jac, groups)
        # The next part is _HCCM, which shouldn't require results
        xxi = hessian_inv
        cov = np.dot(np.dot(xxi, S), xxi.T)
    
        if use_correction:
            #add correction
            nobs, k_params = jac.shape
            n_groups = len(np.unique(groups))
            corr_fact = n_groups / (n_groups - 1.) * ((nobs-1.) / float(nobs - k_params))
    
            cov *= corr_fact
    
        return cov
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions