linearmodels HAC Results in Python and Stata are different

Viewed 12

I use the same data,the results for some reason don't agree.I dont konw why.the code in python is cov_type=hac,the code in stata is newey y x1 x2. python code:

import wooldridge as woo
import pandas as pd
import numpy as np
import statsmodels.api as sm
import statsmodels.formula.api as smf
import patsy as pt

barium = pd.read_csv(r'C:\Users\mi\Anaconda3\Lib\site-packages\wooldridge\datasets\barium.csv\barium.csv')
T = len(barium)
barium.index = pd.date_range(start='1978-02', periods=T, freq='M')

reg = smf.ols(formula='lchnimp ~ lchempi + lgas+'
                      'lrtwex + befile6 + affile6 + afdec6',
              data=barium)
results_HAC = reg.fit(cov_type='HAC', use_t=True,cov_kwds={'maxlags':1}) 
print(results_HAC.summary()) 

Here is the result from Python:

                            OLS Regression Results                            
==============================================================================
Dep. Variable:                lchnimp   R-squared:                       0.305
Model:                            OLS   Adj. R-squared:                  0.271
Method:                 Least Squares   F-statistic:                     7.726
Date:                Thu, 08 Sep 2022   Prob (F-statistic):           4.55e-07
Time:                        09:43:08   Log-Likelihood:                -114.79
No. Observations:                 131   AIC:                             243.6
Df Residuals:                     124   BIC:                             263.7
Df Model:                           6                                         
Covariance Type:                  HAC                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept    -17.8030     22.761     -0.782      0.436     -62.853      27.247
lchempi        3.1172      0.527      5.919      0.000       2.075       4.160
lgas           0.1964      1.011      0.194      0.846      -1.805       2.198
lrtwex         0.9830      0.411      2.393      0.018       0.170       1.796
befile6        0.0596      0.253      0.236      0.814      -0.440       0.560
affile6       -0.0324      0.265     -0.122      0.903      -0.557       0.493
afdec6        -0.5652      0.246     -2.293      0.024      -1.053      -0.077
==============================================================================
Omnibus:                        9.160   Durbin-Watson:                   1.458
Prob(Omnibus):                  0.010   Jarque-Bera (JB):                9.978
Skew:                          -0.491   Prob(JB):                      0.00681
Kurtosis:                       3.930   Cond. No.                     9.62e+03
==============================================================================

Notes:
[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 1 lags and without small sample correction
[2] The condition number is large, 9.62e+03. This might indicate that there are
strong multicollinearity or other numerical problems.

stata code:

import delimited "C:\Users\mi\Anaconda3\Lib\site-packages\wooldridge\datasets\barium.csv\barium.csv", clear 
tsset t
newey lchnimp lchempi lgas lrtwex befile6 affile6 afdec6,lag(1)

Here is the result from Stata:

Regression with Newey–West standard errors      Number of obs     =        131
Maximum lag = 1                                 F(  6,       124) =       7.31
                                                Prob > F          =     0.0000

------------------------------------------------------------------------------
             |             Newey–West
     lchnimp | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
     lchempi |   3.117193   .5413271     5.76   0.000     2.045755    4.188631
        lgas |   .1963504   1.039428     0.19   0.850    -1.860969     2.25367
      lrtwex |   .9830183   .4222467     2.33   0.022     .1472738    1.818763
     befile6 |   .0595739    .259669     0.23   0.819    -.4543837    .5735316
     affile6 |  -.0324064   .2726479    -0.12   0.906    -.5720529    .5072401
      afdec6 |   -.565245    .253352    -2.23   0.027      -1.0667   -.0637904
       _cons |    -17.803   23.39453    -0.76   0.448    -64.10733    28.50133
------------------------------------------------------------------------------

the std.error in Python and Stata is different,but I DONT know why. I use the HAC in Python and use newey in stata.

0 Answers
Related