econmethods 1.3__tar.gz → 1.4__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: 1.3
3
+ Version: 1.4
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
@@ -202,7 +202,8 @@ class HausmanOneWay:
202
202
  1 - your temporal window per panel. The data must be homogenous, e.g. only years, months, etc.
203
203
  2 - Your target variable.
204
204
  3+ - your exogenous variables.
205
- - *level*: the statistical test significance level.
205
+ - *level*: the statistical test significance level.
206
+ - *force_GLS*: Choose if MLE diverges.
206
207
  ---------
207
208
  METHODOLOGY:
208
209
  ------
@@ -214,10 +215,11 @@ class HausmanOneWay:
214
215
  -
215
216
  - Via instance.verdict() prints the verdict of the Hausman test according to the given parameters.
216
217
  '''
217
- def __init__(self, data: pd.DataFrame, level: int = 5) -> None:
218
+ def __init__(self, data: pd.DataFrame, force_GLS: bool = False, level: int = 5) -> None:
218
219
  self.__df = data
219
220
  self.__exog = len(data.columns[3:])
220
221
  self.__l =[]
222
+ self.__fgls = force_GLS
221
223
  for i in range(1, self.__exog+1):
222
224
  self.__l.append(f'x{i}')
223
225
  self.__df.columns = ['SpUnit', 'time', 'target'] + self.__l
@@ -240,8 +242,9 @@ class HausmanOneWay:
240
242
  if sigma_u <= 0:
241
243
  sigma_u = 0
242
244
  elif sigma_u > 0:
243
- self.__RE = 'MLE'
244
- return None
245
+ if not self.__fgls:
246
+ self.__RE = 'MLE'
247
+ return None
245
248
  sig = np.full((self.__T, self.__T), sigma_u)
246
249
  np.fill_diagonal(sig, sigma2)
247
250
  matrix = np.kron(np.eye(self.__N), sig)
@@ -309,6 +312,7 @@ class FECM:
309
312
  - *include_x_diffs*: Specify whether the model should include the differences of exogenous variables. Defaults to True.
310
313
  - *intercept*: Specify whether the ECM model should have an intercept. Defaults to True.
311
314
  - *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.
315
+ - *lr_const*: Specify whether the long-run model should have a constant.
312
316
  ----
313
317
  RETURNS:
314
318
  --
@@ -318,7 +322,7 @@ class FECM:
318
322
  If a CCE- method is chosen:
319
323
  - The AR(d) estimation results to forecast the cross-sectional mean | key = "ar"
320
324
  '''
321
- def __init__(self, df: pd.DataFrame, effects: str = 'rand', trend: int = 0, n_lags: int = 1, method: str = 'MG', coint: str | list[str] = 'x1', include_x_diffs: bool = True, intercept: bool = True, stat_vars: pd.DataFrame|None = None) -> None:
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', include_x_diffs: bool = True, intercept: bool = True, stat_vars: pd.DataFrame|None = None, lr_const: bool = False) -> None:
322
326
  self.__df = df
323
327
  self.__eff = effects.lower()
324
328
  self.__t = trend
@@ -331,6 +335,7 @@ class FECM:
331
335
  self.__mean_names = ['target_avg']
332
336
  self.__x_difs = include_x_diffs
333
337
  self.__stat = []
338
+ self.__lr_c = lr_const
334
339
  if stat_vars is not None:
335
340
  for i in range(1, len(stat_vars.columns[2:])+1):
336
341
  self.__stat.append(f'stat{i}')
@@ -393,7 +398,7 @@ class FECM:
393
398
  means = means.drop(columns=[f'{var}_1'])
394
399
  return means
395
400
 
396
- def build_GLS(self, w_err: float) -> pd.DataFrame:
401
+ def build_GLS(self, w_err: float) -> np.ndarray:
397
402
  re = self.__lr_df.copy(deep=True)
398
403
  sigma2 = np.sum((sm.OLS(re.iloc[:, 2], sm.add_constant(re.iloc[:, 3:])).fit()).resid**2) / (self.__N*self.__T - self.__exog)
399
404
  sigma_u = sigma2 - w_err
@@ -413,13 +418,21 @@ class FECM:
413
418
  def __estimate_lr(self) -> pd.DataFrame:
414
419
  if self.__eff == 'fix':
415
420
  lr_fe = self.build_FE()
416
- res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
421
+ if self.__lr_c:
422
+ res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
423
+ else:
424
+ res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
417
425
  return res_lr
418
426
  else:
419
427
  lr_fe = self.build_FE()
420
- resid = np.sum(sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit().resid**2) / (self.__N*(self.__T - 1) - self.__exog)
421
- lr_re_matrix = self.build_GLS(resid)
422
- return sm.GLS(self.__lr_df.loc[:, 'target'], sm.add_constant(self.__lr_df.iloc[:, 3:]), lr_re_matrix).fit()
428
+ if self.__lr_c:
429
+ resid = np.sum(sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit().resid**2) / (self.__N*(self.__T - 1) - self.__exog)
430
+ lr_re_matrix = self.build_GLS(resid)
431
+ return sm.GLS(self.__lr_df.loc[:, 'target'], sm.add_constant(self.__lr_df.iloc[:, 3:]), lr_re_matrix).fit()
432
+ else:
433
+ resid = np.sum(sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit().resid**2) / (self.__N*(self.__T - 1) - self.__exog)
434
+ lr_re_matrix = self.build_GLS(resid)
435
+ return sm.GLS(self.__lr_df.loc[:, 'target'], self.__lr_df.iloc[:, 3:], lr_re_matrix).fit()
423
436
 
424
437
  def select_ar(self) -> Any:
425
438
  current_d = self.__lag+1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 1.3
3
+ Version: 1.4
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 = 'v1.3',
8
+ version = 'v1.4',
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