Skip to content

hat matrix, HC2, HC3 for WLS versus Stata #1209

Open

Description

@josef-pkt

It's not clear what definition of the hatmatrix Stata uses with aweights

testing robust HCx for WLS against Stata regress with aweights

HC1 matches after trivial change (resid -> wresid)
HC2 and HC3 differ, because the diagonal of the hat matrix is different, after regress with aweights (Stata at least divides one more time by weights.)

making the trivial change resid -> wresid, exog -> wexog, I get the same results with WLS or OLS after rescaling/weighting

>>> resw = WLS(dtapa_endog, add_constant(dtapa_exog[['value', 'capital']], prepend=False), weights=1./dtapa_exog['value']).fit()
>>> resw_h2 = resw.get_robustcov_results(cov_type='HC2', use_t=True)
>>> weights_sqrt=np.sqrt(1./np.asarray(dtapa_exog['value']))
>>> resww.params
array([ 0.11694307,  0.10410757, -9.27233358])
>>> resww.bse
array([ 0.00555499,  0.01306514,  3.38487221])
>>> resww_h2 = resww.get_robustcov_results(cov_type='HC2', use_t=True)
>>> resww_h2.bse
array([ 0.00770722,  0.00995744,  2.36858154])
>>> resw_h2.bse
array([ 0.00770722,  0.00995744,  2.36858154])

however Stata gets

. regress invest mvalue kstock [aw=1/mvalue], vce(hc2)
(sum of wgt is   7.3221e-01)

Linear regression                                      Number of obs =     200
                                                       F(  2,   197) =   36.35
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.7728
                                                       Root MSE      =  35.178

------------------------------------------------------------------------------
             |             Robust HC2
      invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      mvalue |   .1169431   .0138133     8.47   0.000     .0897021    .1441841
      kstock |   .1041076   .0210187     4.95   0.000     .0626569    .1455582
       _cons |  -9.272334   6.059023    -1.53   0.128    -21.22121    2.676539
------------------------------------------------------------------------------

I like our results better.
Note Stata has a big increase in standard errors between weighted and unweighted for the cases of HC2 and HC3, but not for HC1 which doesn't depend on hat matrix.

There will be other cases where we can test against Stata for specific models with non-spherical variance, Panel, HetGLS, GLSAR, ...

Activity

  1. jseabold commented on Sep 26, 2014

    @jseabold
    Member

    Is there something to do here?

  2. modified the milestones: 0.7, 0.6 on Sep 26, 2014
  3. josef-pkt commented on Sep 26, 2014

    @josef-pkt
    MemberAuthor

    not for 0.6. This is mainly a reminder and reference, until I figure this out.

    The definition of hatmatrix across models is an open issue. (There are two definitions when we have weights or GLS whitening, but I don't know when we are supposed to use which.)
    For the WLS/GLS sandwiches I need other test cases, to check what FGLS and similar are supposed to be doing.

    corrections like HC2, HC3 need to be extended to other sandwiches.

  4. modified the milestones: 0.9, 0.7 on Jun 13, 2016
  5. modified the milestones: 0.10, 0.9 on Jun 11, 2017
  6. josef-pkt commented on Dec 9, 2019

    @josef-pkt
    MemberAuthor
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions