0

I have a dataframe shown below on which I would like to calculate the first difference estimator between different columns. I found this package, but an unsure of how to implement it...also, are co-variates allowed? I am new to both python and statistics so any help would be appreciated!

Package I found: https://bashtage.github.io/linearmodels/doc/panel/models.html#linearmodels.panel.model.FirstDifferenceOLS

How to format data: https://bashtage.github.io/linearmodels/doc/panel/examples/data-formats.html

My Data (now multiindexed):

       vix                  eff                  bloom 
       time  VIX_close  FEDFUNDS       time       time   
 2017-06-16  10.380000  3.020000 1993-01-01 1993-01-01   
 2017-06-15  10.640000  3.025000 1993-02-01 1993-01-02   

My attempt:

mod = FirstDifferenceOLS(master.FEDFUNDS, master.Kincaid)
res = mod.fit(cov_type='robust')

Which results in:

ValueError: Series can only be used with a 2-level MultiIndex
Graham Streich
  • 874
  • 3
  • 15
  • 31

1 Answers1

2

There is an easy way to do this!

1) Leave data as is (aka do NOT multi index and do NOT use package)

Code:

ARI        Flesch     Kincaid       time    VIX_close  FEDFUNDS  
14.289911  36.843078  13.187598 2004-03-01  17.223000  1.431333   
14.825867  39.550341  13.849544 2004-04-01  16.304333  1.381667 

2) Use pandas to calculate first difference with .diff() function:

differs = master.diff()

3) Regress the differences:

result = sm.ols(formula="Kincaid ~ VIX_close", data=differs).fit()

4) Ta-da -- you're done!

Graham Streich
  • 874
  • 3
  • 15
  • 31