econmethods 3__tar.gz → 3.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {econmethods-3 → econmethods-3.0.1}/PKG-INFO +1 -1
- {econmethods-3 → econmethods-3.0.1}/econmethods/Lib.py +68 -49
- {econmethods-3 → econmethods-3.0.1}/econmethods.egg-info/PKG-INFO +1 -1
- {econmethods-3 → econmethods-3.0.1}/setup.py +1 -1
- {econmethods-3 → econmethods-3.0.1}/README.md +0 -0
- {econmethods-3 → econmethods-3.0.1}/econmethods/CADF_Crit_Values.xlsx +0 -0
- {econmethods-3 → econmethods-3.0.1}/econmethods/__init__.py +0 -0
- {econmethods-3 → econmethods-3.0.1}/econmethods.egg-info/SOURCES.txt +0 -0
- {econmethods-3 → econmethods-3.0.1}/econmethods.egg-info/dependency_links.txt +0 -0
- {econmethods-3 → econmethods-3.0.1}/econmethods.egg-info/requires.txt +0 -0
- {econmethods-3 → econmethods-3.0.1}/econmethods.egg-info/top_level.txt +0 -0
- {econmethods-3 → econmethods-3.0.1}/setup.cfg +0 -0
|
@@ -312,6 +312,9 @@ class FECM:
|
|
|
312
312
|
- *stat_vars*: a DataFrame of the same format as "df" - includes variables that will not be differenced and included into the ECM in their raw form. Ensure these variables are I(0). Defaults to None.
|
|
313
313
|
- *lr_const*: Specify whether the long-run model should have a constant.
|
|
314
314
|
- *autorem*: Enables/Disables automatic removal of insignificant regression coefficients in the ECM. Defaults to True.
|
|
315
|
+
- *remove_difs*: Remove the cointegration vector differences. Enabling this invalidates autorem. Defaults to False.
|
|
316
|
+
- *remove_lr_ins*: Enables/Disables automatic removal of insignificant regression coefficients in the long-run model. Defaults to False.
|
|
317
|
+
- *sf*: Your significance level.
|
|
315
318
|
----
|
|
316
319
|
RETURNS:
|
|
317
320
|
--
|
|
@@ -321,20 +324,23 @@ class FECM:
|
|
|
321
324
|
If a CCE- method is chosen:
|
|
322
325
|
- The AR(d) estimation results to forecast the cross-sectional mean | key = "ar"
|
|
323
326
|
'''
|
|
324
|
-
def __init__(self, df: pd.DataFrame, effects: str = 'rand', trend: int = 0, n_lags: int = 1, method: str = 'MG', coint: str | list[str] = 'x1', intercept: bool = True, stat_vars: pd.DataFrame|None = None, lr_const: bool = False, autorem: bool = True) -> None:
|
|
327
|
+
def __init__(self, df: pd.DataFrame, effects: str = 'rand', trend: int = 0, n_lags: int = 1, method: str = 'MG', coint: str | list[str] = 'x1', intercept: bool = True, stat_vars: pd.DataFrame|None = None, lr_const: bool = False, autorem: bool = True, remove_difs: bool = False, remove_lr_ins: bool = False, sf: float = 0.05) -> None:
|
|
325
328
|
self.__df = df
|
|
326
329
|
self.__eff = effects.lower()
|
|
327
330
|
self.__t = trend
|
|
328
331
|
self.__autorem = autorem
|
|
329
332
|
self.__C = intercept
|
|
330
333
|
self.__lag = n_lags
|
|
334
|
+
self.sf = sf
|
|
331
335
|
self.x_difs = []
|
|
336
|
+
self.__remove_difs = remove_difs
|
|
332
337
|
self.__method = method.lower()
|
|
333
338
|
self.__exog = len(df.columns[3:])
|
|
334
339
|
self.__l =[]
|
|
335
340
|
self.__stat_vars = stat_vars
|
|
336
341
|
self.__mean_names = ['target_avg_l1']
|
|
337
342
|
self.__stat = []
|
|
343
|
+
self.__lr_autorem = remove_lr_ins
|
|
338
344
|
self.__lr_c = lr_const
|
|
339
345
|
if stat_vars is not None:
|
|
340
346
|
for i in range(1, len(stat_vars.columns[2:])+1):
|
|
@@ -420,20 +426,20 @@ class FECM:
|
|
|
420
426
|
res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
|
|
421
427
|
else:
|
|
422
428
|
res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if self.__lr_c:
|
|
433
|
-
res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
|
|
429
|
+
if self.__lr_autorem:
|
|
430
|
+
while True:
|
|
431
|
+
flag = True
|
|
432
|
+
for coef, t in zip(res_lr.params.index, res_lr.pvalues):
|
|
433
|
+
if t > self.sf:
|
|
434
|
+
lr_fe = lr_fe.drop(columns=[coef])
|
|
435
|
+
flag=False
|
|
436
|
+
if flag:
|
|
437
|
+
break
|
|
434
438
|
else:
|
|
435
|
-
|
|
436
|
-
|
|
439
|
+
if self.__lr_c:
|
|
440
|
+
res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
|
|
441
|
+
else:
|
|
442
|
+
res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
|
|
437
443
|
return res_lr
|
|
438
444
|
else:
|
|
439
445
|
lr_fe = self.build_FE()
|
|
@@ -514,27 +520,34 @@ class FECM:
|
|
|
514
520
|
else:
|
|
515
521
|
est.append(sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit())
|
|
516
522
|
if self.__autorem:
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
523
|
+
if not self.__remove_difs:
|
|
524
|
+
while True:
|
|
525
|
+
ts = []
|
|
526
|
+
flag = True
|
|
527
|
+
if max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[1] > self.sf:
|
|
528
|
+
pool = pool.drop(columns=[max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[0]])
|
|
529
|
+
flag=False
|
|
530
|
+
for i in self.x_difs:
|
|
531
|
+
try:
|
|
532
|
+
tmp = est[0].pvalues[i] <= self.sf
|
|
533
|
+
if tmp:
|
|
534
|
+
ts.append(1)
|
|
535
|
+
except Exception:
|
|
527
536
|
ts.append(1)
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if flag or len(ts) == len(self.x_difs):
|
|
532
|
-
break
|
|
533
|
-
else:
|
|
534
|
-
if self.__C:
|
|
535
|
-
est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
|
|
537
|
+
|
|
538
|
+
if flag or len(ts) == len(self.x_difs):
|
|
539
|
+
break
|
|
536
540
|
else:
|
|
537
|
-
|
|
541
|
+
if self.__C:
|
|
542
|
+
est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
|
|
543
|
+
else:
|
|
544
|
+
est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
|
|
545
|
+
else:
|
|
546
|
+
pool = pool.drop(columns=[self.x_difs])
|
|
547
|
+
if self.__C:
|
|
548
|
+
est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
|
|
549
|
+
else:
|
|
550
|
+
est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
|
|
538
551
|
return est
|
|
539
552
|
|
|
540
553
|
def mg_algorithm(self) -> pd.DataFrame:
|
|
@@ -568,29 +581,35 @@ class FECM:
|
|
|
568
581
|
dct['lr_res'] = self.__lr
|
|
569
582
|
res = self.mg_algorithm()
|
|
570
583
|
if self.__autorem:
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
584
|
+
if not self.__remove_difs:
|
|
585
|
+
while True:
|
|
586
|
+
ts = []
|
|
587
|
+
flag = True
|
|
588
|
+
if max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[1] > self.sf:
|
|
589
|
+
self.__sr = self.build_sr([max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[0]])
|
|
590
|
+
flag=False
|
|
591
|
+
for i in self.x_difs:
|
|
592
|
+
try:
|
|
593
|
+
tmp = res['coefs']['T-pvalues'][i] <= 0.1
|
|
594
|
+
if tmp:
|
|
595
|
+
ts.append(1)
|
|
596
|
+
except Exception:
|
|
581
597
|
ts.append(1)
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
598
|
+
if flag or len(ts) == len(self.x_difs):
|
|
599
|
+
break
|
|
600
|
+
else:
|
|
601
|
+
res = self.mg_algorithm()
|
|
602
|
+
else:
|
|
603
|
+
self.__sr = self.build_sr([self.x_difs])
|
|
604
|
+
res = self.mg_algorithm()
|
|
605
|
+
|
|
588
606
|
|
|
589
607
|
dct['sr_res'] = res
|
|
590
608
|
return dct
|
|
591
609
|
|
|
592
610
|
def __del__(self) -> None:
|
|
593
611
|
pass
|
|
612
|
+
|
|
594
613
|
class CDTwoWay:
|
|
595
614
|
'''
|
|
596
615
|
Implementation of the CD test to validate/reject cross-sectional dependence.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|