1

I found statsmodels.sandbox.regression.gmm for gmm regressions but dont understand how I can use it with Newey West errors in a simple way.

Maybe let me outline my specific case: I have only one explanatory variable and one dependent variable. this is the code I am using:

import numpy as np 
import pandas as pd from statsmodels.sandbox.regression.gmm 
import GMM 

X = var_beta["f1"] 
X = sm.add_constant(X) 
y = var_beta["f2"] 

model_1 = GMM(y, X, None) 
results = model_1.fit(weights_method = 'hac', wargs={'maxlag': 30}) 

This returns:

AttributeError: 'GMM' object has no attribute 'fitstart'. 

And if I add

beta = np.array([0.0061,-0.3283])
results = model_1.fit(beta, optim_method='nm', weights_method = 'hac',wargs={'maxlag': 30})

I get

numpy.linalg.LinAlgError: SVD did not converge

Although I do not understand why I should add this. Found it in an example and do not know what the equivalent for my sample would be. Regardless, it would return this error message anyways.

What am I doing wrong? Is it because I did not specify any instruments or moment conditions? The problem is that I am basing the procedure on a paper which only states:

"We estimate the regressions using the generalized methods of moments (GMM), with the weighting matrix computed according to Newey and West (1987) with 30 lags for the overlapping daily series"

But the authors do not elaborate any further, so I would not know which moment restrictions or instruments to use (if I have to use them at all). The regression (a normal CAPM regression) is super simple and should look like

Regression

where the left-hand-side corresponds to y, and the right-hand-side to X from above in the code respectively.

I have to admit that I am completely new to the whole GMM procedure and me failing to apply the code could be due to my non-existent expertise within the domain. It is just one of many components that I have to apply in my Master thesis and this one really is giving me a headache.

Gaggles
  • 11
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 10 '22 at 20:39

1 Answers1

0

When fitting using GMM's .fit() method, specify weights_method argument to choose covariance matrix estimation procedure, for Newey-West you need weights_method = 'hac'.

  • I already figured this one out but thank you for your answer! I am having a specific problem with using this procedure however. As I am new to stackoverflow I just realised that I was not precise enough in my question. I therefore updated it. Please have a look and tell me whether you can help. And again, thank you. I am really struggling with this at the moment and it already costs me way too much time:( – Gaggles Apr 11 '22 at 19:57
  • any take on the new problem specification? – Gaggles Apr 14 '22 at 15:11
  • It is not possible to say anything specific without a reproducible example, i.e. without data. In any case, I wouldn't touch anything in the `sandbox` since these modules are largely unfinished/untested. You will be much better off using R for this if possible. – Always Right Never Left Apr 15 '22 at 13:29
  • And of course you'll need to specify moment conditions. If I understood your usecase correctly, you want to estimate a univariate linear regression. Then your moment condition will simply be orthogonality of your covariates and residuals. You can look at some examples here: https://stackoverflow.com/questions/49272902/issue-with-using-statsmodels-sandbox-regression-gmm-gmm – Always Right Never Left Apr 15 '22 at 13:51