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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 2.8
3
+ Version: 3
4
4
  Summary: A python package implementing various econometrical tests and estimators
5
5
  Home-page: https://github.com/NaturionBG/econmethods
6
6
  Author: NaturionBG
@@ -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
- while True:
514
- flag = True
515
- if max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[1] > 0.06:
516
- pool = pool.drop(columns=[max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[0]])
517
- flag=False
518
- if flag:
519
- break
520
- else:
521
- if self.__C:
522
- est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
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
- est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
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
- while True:
558
- flag = True
559
- if max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[1] > 0.06:
560
- self.__sr = self.build_sr([max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[0]])
561
- flag=False
562
- if flag:
563
- break
564
- else:
565
- res = self.mg_algorithm()
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 2.8
3
+ Version: 3
4
4
  Summary: A python package implementing various econometrical tests and estimators
5
5
  Home-page: https://github.com/NaturionBG/econmethods
6
6
  Author: NaturionBG
@@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
5
5
 
6
6
  setup(
7
7
  name = 'econmethods',
8
- version = 'v2.8',
8
+ version = 'v3',
9
9
  description='A python package implementing various econometrical tests and estimators',
10
10
  packages = find_packages(),
11
11
  long_description=long_desc,
File without changes
File without changes