Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

python - Error in Statsmodels Newey-West (robust) variance covariance matrix

For some purposes, I need to regress several time series on a constant only. The LHS variable (endog in statsmodels.OLS) looks like this (call it df)

                  0         1         2   ...        22        23        24
1963-07-31  0.023377  0.008570  0.014301  ...  0.018695  0.002118 -0.004114
1963-08-31 -0.021446 -0.040604 -0.036767  ...  0.008298  0.041109  0.021422
1963-09-30 -0.004617  0.027603  0.007309  ...  0.003580  0.012020 -0.020118
1963-10-31 -0.009448 -0.026168 -0.005506  ... -0.017357  0.009267 -0.010689
1963-11-30 -0.017838 -0.026986 -0.004256  ... -0.007105 -0.012545  0.022867
             ...       ...       ...  ...       ...       ...       ...
2014-01-31  0.071162  0.001646  0.003898  ... -0.011182 -0.020756 -0.020589
2014-02-28 -0.014462 -0.018556 -0.008404  ... -0.008159  0.003452 -0.015939
2014-03-31 -0.048761  0.004809  0.001056  ...  0.021843  0.035821  0.033281
2014-04-30 -0.051516 -0.037292 -0.025415  ...  0.036954  0.041226  0.000193
2014-05-31 -0.033725 -0.026068 -0.013516  ...  0.016622  0.010879  0.006987

and the RHS (exog in statsmodels.OLS) is a column of ones, call it x. I am trying to get a robust variance-covariance matrix of the estimates by running

mod=sm.OLS(endog=df, exog=x)
res=mod.fit(cov_type='HAC',cov_kwds={'maxlags':1})

but I get the error

ValueError: shapes (2,611,610) and (610,611,2) not aligned: 610 (dim 2) != 611 (dim 1)

Why is that the case? How do I need to modify this to make it works?

question from:https://stackoverflow.com/questions/65952179/error-in-statsmodels-newey-west-robust-variance-covariance-matrix

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...