Skip to content
Advertisement

How to do test of equality of coefficient for 2SLS in Statsmodels or Linearmodels?

So if I ran an experiment with multiple treatment groups and a control, I would analyse the results using Statsmodel ols to see if any of the treatment group were statistically different from the control group:

y ~ C(treatment_group, Treatment(‘Control’)

I would then run results.t_test_pairwise() to find out if the coefficients of each treatment group were equal. I.e. to know whether the results of each treatment group were statistically significantly different to one another.

In the current situation, rather than just running a standard ols, I am using Statsmodel/Linearmodel’s 2SLS to analyse an instrumental variable. I can run the analysis perfectly fine, and I get the results. But now I need to see whether the coefficients of the different instruments (the three different treatment groups) are the same, so I know whether the different treatment groups vary in their effect.

Code for statsmodel:

from statsmodels.sandbox.regression.gmm import IV2SLS as SM2SLS
model = SM2SLS(tdf[endog],tdf['elect_lpd'],tdf[inst]).fit()

Or for Linearmodel:

model = LM2SLS(tdf.elect_lpd, tdf[controls], tdf[endog], tdf[inst]).fit(cov_type='clustered')

Josef’s response here, suggests that you can use the wald t-test, but I need to use the restriction matrix rather than the formula. So if anyone has any ideas of how to do that, that would be much appreciated.

Advertisement

Answer

If anyone else get’s stuck with this…I figured out the solution when using Linearmodels.

So after running the model:

model = LM2SLS(tdf.elect_lpd, tdf[controls], tdf[endog], tdf[inst]).fit(cov_type='clustered')

You can then run wald test to compare differences between each of your treatment group. In my case, I had two treatment groups (sbs & wing):

test.wald_test(formula = ['endog_sbs = endog_wing'])
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement