econmethods 2.8__tar.gz → 3__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.8 → econmethods-3}/PKG-INFO +1 -1
- {econmethods-2.8 → econmethods-3}/econmethods/Lib.py +44 -26
- {econmethods-2.8 → econmethods-3}/econmethods.egg-info/PKG-INFO +1 -1
- {econmethods-2.8 → econmethods-3}/setup.py +1 -1
- {econmethods-2.8 → econmethods-3}/README.md +0 -0
- {econmethods-2.8 → econmethods-3}/econmethods/CADF_Crit_Values.xlsx +0 -0
- {econmethods-2.8 → econmethods-3}/econmethods/__init__.py +0 -0
- {econmethods-2.8 → econmethods-3}/econmethods.egg-info/SOURCES.txt +0 -0
- {econmethods-2.8 → econmethods-3}/econmethods.egg-info/dependency_links.txt +0 -0
- {econmethods-2.8 → econmethods-3}/econmethods.egg-info/requires.txt +0 -0
- {econmethods-2.8 → econmethods-3}/econmethods.egg-info/top_level.txt +0 -0
- {econmethods-2.8 → econmethods-3}/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.
|
|
@@ -312,6 +311,7 @@ class FECM:
|
|
|
312
311
|
- *intercept*: Specify whether the ECM model should have an intercept. Defaults to True.
|
|
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.
|
|
314
|
+
- *autorem*: Enables/Disables automatic removal of insignificant regression coefficients in the ECM. Defaults to True.
|
|
315
315
|
----
|
|
316
316
|
RETURNS:
|
|
317
317
|
--
|
|
@@ -321,12 +321,14 @@ class FECM:
|
|
|
321
321
|
If a CCE- method is chosen:
|
|
322
322
|
- The AR(d) estimation results to forecast the cross-sectional mean | key = "ar"
|
|
323
323
|
'''
|
|
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) -> None:
|
|
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:
|
|
325
325
|
self.__df = df
|
|
326
326
|
self.__eff = effects.lower()
|
|
327
327
|
self.__t = trend
|
|
328
|
+
self.__autorem = autorem
|
|
328
329
|
self.__C = intercept
|
|
329
330
|
self.__lag = n_lags
|
|
331
|
+
self.x_difs = []
|
|
330
332
|
self.__method = method.lower()
|
|
331
333
|
self.__exog = len(df.columns[3:])
|
|
332
334
|
self.__l =[]
|
|
@@ -340,6 +342,7 @@ class FECM:
|
|
|
340
342
|
self.__stat_vars.columns = ['SpUnit', 'time'] + self.__stat
|
|
341
343
|
for i in range(1, self.__exog+1):
|
|
342
344
|
self.__l.append(f'x{i}')
|
|
345
|
+
self.x_difs.append(f'x{i}_diff')
|
|
343
346
|
self.__mean_names.append(f'x{i}_avg')
|
|
344
347
|
self.__df.columns = ['SpUnit', 'time', 'target'] + self.__l
|
|
345
348
|
if isinstance(coint, list):
|
|
@@ -510,18 +513,28 @@ class FECM:
|
|
|
510
513
|
est.append(sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit())
|
|
511
514
|
else:
|
|
512
515
|
est.append(sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit())
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
516
|
+
if self.__autorem:
|
|
517
|
+
while True:
|
|
518
|
+
ts = []
|
|
519
|
+
flag = True
|
|
520
|
+
if max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[1] > 0.06:
|
|
521
|
+
pool = pool.drop(columns=[max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[0]])
|
|
522
|
+
flag=False
|
|
523
|
+
for i in self.x_difs:
|
|
524
|
+
try:
|
|
525
|
+
tmp = est[0].pvalues[i] <= 0.05
|
|
526
|
+
if tmp:
|
|
527
|
+
ts.append(1)
|
|
528
|
+
except Exception:
|
|
529
|
+
ts.append(1)
|
|
530
|
+
|
|
531
|
+
if flag or len(ts) == len(self.x_difs):
|
|
532
|
+
break
|
|
523
533
|
else:
|
|
524
|
-
|
|
534
|
+
if self.__C:
|
|
535
|
+
est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
|
|
536
|
+
else:
|
|
537
|
+
est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
|
|
525
538
|
return est
|
|
526
539
|
|
|
527
540
|
def mg_algorithm(self) -> pd.DataFrame:
|
|
@@ -554,25 +567,30 @@ class FECM:
|
|
|
554
567
|
elif self.__method == 'ccemg' or self.__method == 'mg':
|
|
555
568
|
dct['lr_res'] = self.__lr
|
|
556
569
|
res = self.mg_algorithm()
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
570
|
+
if self.__autorem:
|
|
571
|
+
while True:
|
|
572
|
+
ts = []
|
|
573
|
+
flag = True
|
|
574
|
+
if max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[1] > 0.06:
|
|
575
|
+
self.__sr = self.build_sr([max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[0]])
|
|
576
|
+
flag=False
|
|
577
|
+
for i in self.x_difs:
|
|
578
|
+
try:
|
|
579
|
+
tmp = res['coefs']['T-pvalues'][i] <= 0.05
|
|
580
|
+
if tmp:
|
|
581
|
+
ts.append(1)
|
|
582
|
+
except Exception:
|
|
583
|
+
ts.append(1)
|
|
584
|
+
if flag or len(ts) == len(self.x_difs):
|
|
585
|
+
break
|
|
586
|
+
else:
|
|
587
|
+
res = self.mg_algorithm()
|
|
566
588
|
|
|
567
589
|
dct['sr_res'] = res
|
|
568
590
|
return dct
|
|
569
591
|
|
|
570
592
|
def __del__(self) -> None:
|
|
571
593
|
pass
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
594
|
class CDTwoWay:
|
|
577
595
|
'''
|
|
578
596
|
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
|