econmethods 2.9__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-2.9 → econmethods-3.0.1}/PKG-INFO +1 -1
- {econmethods-2.9 → econmethods-3.0.1}/econmethods/Lib.py +71 -38
- {econmethods-2.9 → econmethods-3.0.1}/econmethods.egg-info/PKG-INFO +1 -1
- {econmethods-2.9 → econmethods-3.0.1}/setup.py +1 -1
- {econmethods-2.9 → econmethods-3.0.1}/README.md +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/econmethods/CADF_Crit_Values.xlsx +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/econmethods/__init__.py +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/econmethods.egg-info/SOURCES.txt +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/econmethods.egg-info/dependency_links.txt +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/econmethods.egg-info/requires.txt +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/econmethods.egg-info/top_level.txt +0 -0
- {econmethods-2.9 → econmethods-3.0.1}/setup.cfg +0 -0
|
@@ -278,7 +278,6 @@ class HausmanOneWay:
|
|
|
278
278
|
def __del__(self) -> None:
|
|
279
279
|
pass
|
|
280
280
|
|
|
281
|
-
|
|
282
281
|
class FECM:
|
|
283
282
|
'''
|
|
284
283
|
The implementation of a first-order ECM (Error Correction Model) estimation for panel data.
|
|
@@ -313,6 +312,9 @@ class FECM:
|
|
|
313
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.
|
|
314
313
|
- *lr_const*: Specify whether the long-run model should have a constant.
|
|
315
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.
|
|
316
318
|
----
|
|
317
319
|
RETURNS:
|
|
318
320
|
--
|
|
@@ -322,19 +324,23 @@ class FECM:
|
|
|
322
324
|
If a CCE- method is chosen:
|
|
323
325
|
- The AR(d) estimation results to forecast the cross-sectional mean | key = "ar"
|
|
324
326
|
'''
|
|
325
|
-
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:
|
|
326
328
|
self.__df = df
|
|
327
329
|
self.__eff = effects.lower()
|
|
328
330
|
self.__t = trend
|
|
329
331
|
self.__autorem = autorem
|
|
330
332
|
self.__C = intercept
|
|
331
333
|
self.__lag = n_lags
|
|
334
|
+
self.sf = sf
|
|
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):
|
|
@@ -342,6 +348,7 @@ class FECM:
|
|
|
342
348
|
self.__stat_vars.columns = ['SpUnit', 'time'] + self.__stat
|
|
343
349
|
for i in range(1, self.__exog+1):
|
|
344
350
|
self.__l.append(f'x{i}')
|
|
351
|
+
self.x_difs.append(f'x{i}_diff')
|
|
345
352
|
self.__mean_names.append(f'x{i}_avg')
|
|
346
353
|
self.__df.columns = ['SpUnit', 'time', 'target'] + self.__l
|
|
347
354
|
if isinstance(coint, list):
|
|
@@ -419,20 +426,20 @@ class FECM:
|
|
|
419
426
|
res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
|
|
420
427
|
else:
|
|
421
428
|
res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if self.__lr_c:
|
|
432
|
-
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
|
|
433
438
|
else:
|
|
434
|
-
|
|
435
|
-
|
|
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()
|
|
436
443
|
return res_lr
|
|
437
444
|
else:
|
|
438
445
|
lr_fe = self.build_FE()
|
|
@@ -513,18 +520,34 @@ class FECM:
|
|
|
513
520
|
else:
|
|
514
521
|
est.append(sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit())
|
|
515
522
|
if self.__autorem:
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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:
|
|
536
|
+
ts.append(1)
|
|
537
|
+
|
|
538
|
+
if flag or len(ts) == len(self.x_difs):
|
|
539
|
+
break
|
|
526
540
|
else:
|
|
527
|
-
|
|
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()
|
|
528
551
|
return est
|
|
529
552
|
|
|
530
553
|
def mg_algorithm(self) -> pd.DataFrame:
|
|
@@ -558,15 +581,28 @@ class FECM:
|
|
|
558
581
|
dct['lr_res'] = self.__lr
|
|
559
582
|
res = self.mg_algorithm()
|
|
560
583
|
if self.__autorem:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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:
|
|
597
|
+
ts.append(1)
|
|
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
|
+
|
|
570
606
|
|
|
571
607
|
dct['sr_res'] = res
|
|
572
608
|
return dct
|
|
@@ -574,9 +610,6 @@ class FECM:
|
|
|
574
610
|
def __del__(self) -> None:
|
|
575
611
|
pass
|
|
576
612
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
613
|
class CDTwoWay:
|
|
581
614
|
'''
|
|
582
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
|