econmethods 3.0.1__tar.gz → 3.0.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-3.0.1 → econmethods-3.0.3}/PKG-INFO +1 -1
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods/Lib.py +44 -16
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods.egg-info/PKG-INFO +1 -1
- {econmethods-3.0.1 → econmethods-3.0.3}/setup.py +1 -1
- {econmethods-3.0.1 → econmethods-3.0.3}/README.md +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods/CADF_Crit_Values.xlsx +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods/__init__.py +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods.egg-info/SOURCES.txt +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods.egg-info/dependency_links.txt +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods.egg-info/requires.txt +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/econmethods.egg-info/top_level.txt +0 -0
- {econmethods-3.0.1 → econmethods-3.0.3}/setup.cfg +0 -0
|
@@ -312,19 +312,18 @@ 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.
|
|
315
|
+
- *remove_difs*: Remove the cointegration vector differences. Enabling this invalidates autorem. Passing a string removes that exact variable. Defaults to False.
|
|
316
316
|
- *remove_lr_ins*: Enables/Disables automatic removal of insignificant regression coefficients in the long-run model. Defaults to False.
|
|
317
317
|
- *sf*: Your significance level.
|
|
318
|
+
- *cont_means*: Enable/disable contemporanous means for the CCE- framework. Disabling will cause all means to be lagged by one period. Defaults to True.
|
|
318
319
|
----
|
|
319
320
|
RETURNS:
|
|
320
321
|
--
|
|
321
322
|
A python dictionary (dict) containing:
|
|
322
323
|
- Long-run estimation results | key = "lr_res"
|
|
323
324
|
- ECM (short-run) estimation results | key = "sr_res"\n
|
|
324
|
-
If a CCE- method is chosen:
|
|
325
|
-
- The AR(d) estimation results to forecast the cross-sectional mean | key = "ar"
|
|
326
325
|
'''
|
|
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
|
+
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 | list[str] = False, remove_lr_ins: bool = False, sf: float = 0.05, cont_means: bool = True) -> None:
|
|
328
327
|
self.__df = df
|
|
329
328
|
self.__eff = effects.lower()
|
|
330
329
|
self.__t = trend
|
|
@@ -333,12 +332,20 @@ class FECM:
|
|
|
333
332
|
self.__lag = n_lags
|
|
334
333
|
self.sf = sf
|
|
335
334
|
self.x_difs = []
|
|
336
|
-
self.
|
|
335
|
+
self.__cont_means = cont_means
|
|
336
|
+
if type(remove_difs) == bool:
|
|
337
|
+
self.__remove_difs = remove_difs
|
|
338
|
+
else:
|
|
339
|
+
self.x_difs = np.array(remove_difs)+'_diff'
|
|
340
|
+
self.__remove_difs = True
|
|
337
341
|
self.__method = method.lower()
|
|
338
342
|
self.__exog = len(df.columns[3:])
|
|
339
343
|
self.__l =[]
|
|
340
344
|
self.__stat_vars = stat_vars
|
|
341
|
-
self.
|
|
345
|
+
if not self.__cont_means:
|
|
346
|
+
self.__mean_names = ['target_avg_l1']
|
|
347
|
+
else:
|
|
348
|
+
self.__mean_names = ['target_avg']
|
|
342
349
|
self.__stat = []
|
|
343
350
|
self.__lr_autorem = remove_lr_ins
|
|
344
351
|
self.__lr_c = lr_const
|
|
@@ -348,8 +355,12 @@ class FECM:
|
|
|
348
355
|
self.__stat_vars.columns = ['SpUnit', 'time'] + self.__stat
|
|
349
356
|
for i in range(1, self.__exog+1):
|
|
350
357
|
self.__l.append(f'x{i}')
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
if type(remove_difs) == bool:
|
|
359
|
+
self.x_difs.append(f'x{i}_diff')
|
|
360
|
+
if self.__cont_means:
|
|
361
|
+
self.__mean_names.append(f'x{i}_avg')
|
|
362
|
+
else:
|
|
363
|
+
self.__mean_names.append(f'x{i}_avg_1')
|
|
353
364
|
self.__df.columns = ['SpUnit', 'time', 'target'] + self.__l
|
|
354
365
|
if isinstance(coint, list):
|
|
355
366
|
self.__lr_df = self.__df.copy(deep=True).loc[:, ['SpUnit', 'time', 'target', *coint]]
|
|
@@ -393,9 +404,11 @@ class FECM:
|
|
|
393
404
|
def build_means(self) -> pd.DataFrame:
|
|
394
405
|
mn = self.__df.copy(deep=True)
|
|
395
406
|
mn = mn.set_index('time')
|
|
396
|
-
|
|
407
|
+
if not self.__cont_means:
|
|
408
|
+
means = mn.groupby('time')[['target'] + self.__l].mean().shift(1)
|
|
409
|
+
else:
|
|
410
|
+
means = mn.groupby('time')[['target'] + self.__l].mean()
|
|
397
411
|
means.columns = self.__mean_names
|
|
398
|
-
means['target_avg_l1'] = means['target_avg_l1'].shift(1)
|
|
399
412
|
return means
|
|
400
413
|
|
|
401
414
|
def build_GLS(self, w_err: float) -> np.ndarray:
|
|
@@ -431,7 +444,10 @@ class FECM:
|
|
|
431
444
|
flag = True
|
|
432
445
|
for coef, t in zip(res_lr.params.index, res_lr.pvalues):
|
|
433
446
|
if t > self.sf:
|
|
434
|
-
|
|
447
|
+
if coef != 'const':
|
|
448
|
+
lr_fe = lr_fe.drop(columns=[coef])
|
|
449
|
+
else:
|
|
450
|
+
self.__lr_c = False
|
|
435
451
|
flag=False
|
|
436
452
|
if flag:
|
|
437
453
|
break
|
|
@@ -500,7 +516,11 @@ class FECM:
|
|
|
500
516
|
est.append(sm.OLS(model['target_diff'], sm.add_constant(model.iloc[:, 3:])).fit())
|
|
501
517
|
else:
|
|
502
518
|
est.append(sm.OLS(model['target_diff'], model.iloc[:, 3:]).fit())
|
|
503
|
-
|
|
519
|
+
if 'const' not in drop:
|
|
520
|
+
self.__ccemg_units[i] = self.__ccemg_units[i].drop(columns=drop)
|
|
521
|
+
else:
|
|
522
|
+
self.__C = False
|
|
523
|
+
drop = drop.remove('const')
|
|
504
524
|
return est
|
|
505
525
|
elif self.__method == 'mg':
|
|
506
526
|
units = self.__mg_units
|
|
@@ -510,7 +530,11 @@ class FECM:
|
|
|
510
530
|
est.append(sm.OLS(model['target_diff'], sm.add_constant(model.iloc[:, 3:])).fit())
|
|
511
531
|
else:
|
|
512
532
|
est.append(sm.OLS(model['target_diff'], model.iloc[:, 3:]).fit())
|
|
513
|
-
|
|
533
|
+
if 'const' not in drop:
|
|
534
|
+
self.__mg_units[i] = self.__mg_units[i].drop(columns=drop)
|
|
535
|
+
else:
|
|
536
|
+
self.__C = False
|
|
537
|
+
drop = drop.remove('const')
|
|
514
538
|
return est
|
|
515
539
|
elif self.__method == 'ccep':
|
|
516
540
|
units = self.get_ccemg_frames(self.__lag)
|
|
@@ -525,7 +549,11 @@ class FECM:
|
|
|
525
549
|
ts = []
|
|
526
550
|
flag = True
|
|
527
551
|
if max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[1] > self.sf:
|
|
528
|
-
|
|
552
|
+
to_drop = max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[0]
|
|
553
|
+
if to_drop != 'const':
|
|
554
|
+
pool = pool.drop(columns=[to_drop])
|
|
555
|
+
else:
|
|
556
|
+
self.__C = False
|
|
529
557
|
flag=False
|
|
530
558
|
for i in self.x_difs:
|
|
531
559
|
try:
|
|
@@ -543,7 +571,7 @@ class FECM:
|
|
|
543
571
|
else:
|
|
544
572
|
est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
|
|
545
573
|
else:
|
|
546
|
-
pool = pool.drop(columns=[self.x_difs])
|
|
574
|
+
pool = pool.drop(columns=[*self.x_difs])
|
|
547
575
|
if self.__C:
|
|
548
576
|
est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
|
|
549
577
|
else:
|
|
@@ -600,7 +628,7 @@ class FECM:
|
|
|
600
628
|
else:
|
|
601
629
|
res = self.mg_algorithm()
|
|
602
630
|
else:
|
|
603
|
-
self.__sr = self.build_sr(
|
|
631
|
+
self.__sr = self.build_sr(self.x_difs)
|
|
604
632
|
res = self.mg_algorithm()
|
|
605
633
|
|
|
606
634
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|