diffindiff 1.2.0__tar.gz → 1.2.2__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.2
2
2
  Name: diffindiff
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: diffindiff: Python library for convenient Difference-in-Differences Analyses
5
5
  Author: Thomas Wieland
6
6
  Author-email: geowieland@googlemail.com
@@ -10,7 +10,7 @@ Requires-Dist: pandas
10
10
  Requires-Dist: statsmodels
11
11
  Requires-Dist: matplotlib
12
12
  Requires-Dist: datetime
13
- Requires-Dist: sklearn
13
+ Requires-Dist: scikit-learn
14
14
  Requires-Dist: xgboost
15
15
  Requires-Dist: lightgbm
16
16
  Dynamic: author
@@ -24,6 +24,8 @@ Dynamic: summary
24
24
 
25
25
  This Python library is designed for performing Difference-in-Differences (DiD) analyses in a convenient way. It allows users to construct datasets, define treatment and control groups, and set treatment periods. DiD model analyses may be conducted with both datasets created by built-in functions and ready-to-use external datasets. Both simultaneous and staggered adoption are supported. The library allows for various extensions, such as two-way fixed effects models, group- or individual-specific effects, and post-treatment periods. Additionally, it includes functions for visualizing results, such as plotting DiD coefficients with confidence intervals and illustrating the temporal evolution of staggered treatments.
26
26
 
27
+ The diffindiff package is currently being extensively revised (v2.0.0 and following).
28
+
27
29
 
28
30
  ## Author
29
31
 
@@ -46,6 +48,7 @@ Thomas Wieland [ORCID](https://orcid.org/0000-0001-5168-9846) [EMail](mailto:geo
46
48
  - Including covariates
47
49
  - After-treatment period
48
50
  - Triple Difference (DDD)
51
+ - Multiple treatments
49
52
  - Own counterfactuals
50
53
  - **Visualization**: e.g.
51
54
  - Plot observed and expected time course of treatment and control group
@@ -2,6 +2,8 @@
2
2
 
3
3
  This Python library is designed for performing Difference-in-Differences (DiD) analyses in a convenient way. It allows users to construct datasets, define treatment and control groups, and set treatment periods. DiD model analyses may be conducted with both datasets created by built-in functions and ready-to-use external datasets. Both simultaneous and staggered adoption are supported. The library allows for various extensions, such as two-way fixed effects models, group- or individual-specific effects, and post-treatment periods. Additionally, it includes functions for visualizing results, such as plotting DiD coefficients with confidence intervals and illustrating the temporal evolution of staggered treatments.
4
4
 
5
+ The diffindiff package is currently being extensively revised (v2.0.0 and following).
6
+
5
7
 
6
8
  ## Author
7
9
 
@@ -24,6 +26,7 @@ Thomas Wieland [ORCID](https://orcid.org/0000-0001-5168-9846) [EMail](mailto:geo
24
26
  - Including covariates
25
27
  - After-treatment period
26
28
  - Triple Difference (DDD)
29
+ - Multiple treatments
27
30
  - Own counterfactuals
28
31
  - **Visualization**: e.g.
29
32
  - Plot observed and expected time course of treatment and control group
@@ -2,8 +2,8 @@
2
2
  # Name: didanalysis (diffindiff)
3
3
  # Purpose: Analysis functions for difference-in-differences analyses
4
4
  # Author: Thomas Wieland (geowieland@googlemail.com)
5
- # Version: 1.2.0
6
- # Last update: 2025-03-25 19:30
5
+ # Version: 1.2.2
6
+ # Last update: 2025-04-03 06:55
7
7
  # Copyright (c) 2025 Thomas Wieland
8
8
  #-------------------------------------------------------------------------------
9
9
 
@@ -13,6 +13,7 @@ from statsmodels.formula.api import ols
13
13
  import numpy as np
14
14
  import matplotlib.pyplot as plt
15
15
  from matplotlib.dates import DateFormatter
16
+ import warnings
16
17
  from diffindiff import didtools
17
18
 
18
19
 
@@ -111,6 +112,8 @@ class did_model:
111
112
  self,
112
113
  full = True
113
114
  ):
115
+
116
+ warnings.warn("This function will be fundamentally changed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
114
117
 
115
118
  model_results = self.data[0]
116
119
  model_config = self.data[1]
@@ -497,6 +500,8 @@ class did_model:
497
500
 
498
501
  def effects(self):
499
502
 
503
+ warnings.warn("This function will be replaced by the treatment_effects() function in a future version (v2.0.0 and subsequent versions) of the diffindiff package.", FutureWarning)
504
+
500
505
  model_results = self.data[0]
501
506
 
502
507
  effects_df = pd.DataFrame (columns = ["effect_name", "coef", "SE", "t", "p", "CI_lower", "CI_upper"])
@@ -575,15 +580,21 @@ class did_model:
575
580
 
576
581
  def fixef(self):
577
582
 
583
+ warnings.warn("This function is deprecated and will be removed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
584
+
578
585
  fixed_effects = self.data[4]
579
586
  return fixed_effects
580
587
 
581
588
  def indef(self):
582
589
 
590
+ warnings.warn("This function is deprecated and will be removed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
591
+
583
592
  individual_effects = self.data[5]
584
593
  return individual_effects
585
594
 
586
595
  def groupef(self):
596
+
597
+ warnings.warn("This function is deprecated and will be removed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
587
598
 
588
599
  group_effects = self.data[6]
589
600
  return group_effects
@@ -981,7 +992,9 @@ class did_model:
981
992
  plot_size: list = [7, 6],
982
993
  scale_plot: bool = True
983
994
  ):
984
-
995
+
996
+ warnings.warn("This function is deprecated and will be removed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
997
+
985
998
  effects = self.effects()
986
999
 
987
1000
  if sort_by == "coef":
@@ -1035,6 +1048,8 @@ class did_model:
1035
1048
  central_tendency = "mean"
1036
1049
  ):
1037
1050
 
1051
+ warnings.warn("This function is deprecated and will be removed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
1052
+
1038
1053
  model_config = self.data[1]
1039
1054
  if not model_config["GTE"]:
1040
1055
  raise ValueError ("Model does not include group treatment effects. Set GTE=True an define grouping variable using group_by.")
@@ -1101,6 +1116,8 @@ class did_model:
1101
1116
  show_central_tendency = False,
1102
1117
  central_tendency = "mean"
1103
1118
  ):
1119
+
1120
+ warnings.warn("This function is deprecated and will be removed in a future version (v2.0.0 and subsequent) of the diffindiff package.", FutureWarning)
1104
1121
 
1105
1122
  model_config = self.data[1]
1106
1123
  if not model_config["ITE"]:
@@ -2,8 +2,8 @@
2
2
  # Name: diddata (diffindiff)
3
3
  # Purpose: Creating data for Difference-in-Differences Analysis
4
4
  # Author: Thomas Wieland (geowieland@googlemail.com)
5
- # Version: 1.2.0
6
- # Last update: 2025-03-25 19:28
5
+ # Version: 1.2.2
6
+ # Last update: 2025-04-03 06:59
7
7
  # Copyright (c) 2025 Thomas Wieland
8
8
  #-------------------------------------------------------------------------------
9
9
 
@@ -359,11 +359,6 @@ class did_data:
359
359
 
360
360
  return self
361
361
 
362
- def add_treatment( # TODO ?? hier Funktion, die 1 weiteres Treament hinzufuegt
363
- self
364
- ):
365
- pass
366
-
367
362
  def add_segmentation(
368
363
  self,
369
364
  group_benefit: list
@@ -642,22 +637,6 @@ def create_data(
642
637
 
643
638
  return did_data_all
644
639
 
645
- class counterfactual: # TODO ??
646
- def __init__(
647
- self,
648
- model_results
649
-
650
- ):
651
-
652
- self.data = [
653
- model_results
654
- ]
655
-
656
- def get_modelresults (self):
657
- return self.data[0]
658
-
659
-
660
-
661
640
  def create_counterfactual(
662
641
  data,
663
642
  y: str,
@@ -708,7 +687,7 @@ def create_counterfactual(
708
687
  units = didtools.unique(units_tt[unit_col])
709
688
 
710
689
  if not isnotreatment[0]:
711
- print ("No no-treatment control group")
690
+ print ("No no-treatment control group. Counterfactual will not cover full treatment time.")
712
691
 
713
692
  data_TG = pd.DataFrame(columns = data.columns)
714
693
  for unit in units:
@@ -2,8 +2,8 @@
2
2
  # Name: didtools (diffindiff)
3
3
  # Purpose: Creating data for Difference-in-Differences Analysis
4
4
  # Author: Thomas Wieland (geowieland@googlemail.com)
5
- # Version: 1.2.0
6
- # Last update: 2025-03-25 19:27
5
+ # Version: 1.2.2
6
+ # Last update: 2025-04-03 06:54
7
7
  # Copyright (c) 2025 Thomas Wieland
8
8
  #-------------------------------------------------------------------------------
9
9
 
@@ -143,41 +143,47 @@ def is_parallel(
143
143
  pre_post = False,
144
144
  alpha = 0.05
145
145
  ):
146
-
147
- if pre_post:
148
- return None
149
-
146
+
150
147
  modeldata_isnotreatment = is_notreatment(
151
148
  data = data,
152
149
  unit_col = unit_col,
153
150
  treatment_col = treatment_col
154
- )
155
- if not modeldata_isnotreatment:
156
- return None
151
+ )
152
+
153
+ if pre_post or not modeldata_isnotreatment:
154
+ parallel = "not_tested"
155
+ test_ols_model = None
157
156
 
158
157
  treatment_group = modeldata_isnotreatment[1]
159
- first_day_of_treatment = min(data[(data[unit_col].isin(treatment_group)) & (data[treatment_col] == 1)][time_col])
160
158
 
161
- data_test = data[data[time_col] < first_day_of_treatment].copy()
162
- data_test["TG"] = 0
163
- data_test.loc[data_test[unit_col].isin(treatment_group), "TG"] = 1
164
-
165
- if "date_counter" not in data_test.columns:
166
- data_test = date_counter(
167
- df = data_test,
168
- date_col = time_col,
169
- new_col = "date_counter"
170
- )
171
- data_test["TG_x_t"] = data_test["TG"]*data_test["date_counter"]
172
-
173
- test_ols_model = ols(f'{outcome_col} ~ TG + date_counter + TG_x_t', data = data_test).fit()
174
- coef_TG_x_t_p = test_ols_model.pvalues["TG_x_t"]
175
-
176
- if coef_TG_x_t_p < alpha:
177
- parallel = False
159
+ if len(data[(data[unit_col].isin(treatment_group)) & (data[treatment_col] == 1)]) > 0:
160
+
161
+ first_day_of_treatment = min(data[(data[unit_col].isin(treatment_group)) & (data[treatment_col] == 1)][time_col])
162
+
163
+ data_test = data[data[time_col] < first_day_of_treatment].copy()
164
+ data_test["TG"] = 0
165
+ data_test.loc[data_test[unit_col].isin(treatment_group), "TG"] = 1
166
+
167
+ if "date_counter" not in data_test.columns:
168
+ data_test = date_counter(
169
+ df = data_test,
170
+ date_col = time_col,
171
+ new_col = "date_counter"
172
+ )
173
+ data_test["TG_x_t"] = data_test["TG"]*data_test["date_counter"]
174
+
175
+ test_ols_model = ols(f'{outcome_col} ~ TG + date_counter + TG_x_t', data = data_test).fit()
176
+ coef_TG_x_t_p = test_ols_model.pvalues["TG_x_t"]
177
+
178
+ if coef_TG_x_t_p < alpha:
179
+ parallel = False
180
+ else:
181
+ parallel = True
182
+
178
183
  else:
179
- parallel = True
180
-
184
+ parallel = "not_tested"
185
+ test_ols_model = None
186
+
181
187
  return [
182
188
  parallel,
183
189
  test_ols_model
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: diffindiff
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: diffindiff: Python library for convenient Difference-in-Differences Analyses
5
5
  Author: Thomas Wieland
6
6
  Author-email: geowieland@googlemail.com
@@ -10,7 +10,7 @@ Requires-Dist: pandas
10
10
  Requires-Dist: statsmodels
11
11
  Requires-Dist: matplotlib
12
12
  Requires-Dist: datetime
13
- Requires-Dist: sklearn
13
+ Requires-Dist: scikit-learn
14
14
  Requires-Dist: xgboost
15
15
  Requires-Dist: lightgbm
16
16
  Dynamic: author
@@ -24,6 +24,8 @@ Dynamic: summary
24
24
 
25
25
  This Python library is designed for performing Difference-in-Differences (DiD) analyses in a convenient way. It allows users to construct datasets, define treatment and control groups, and set treatment periods. DiD model analyses may be conducted with both datasets created by built-in functions and ready-to-use external datasets. Both simultaneous and staggered adoption are supported. The library allows for various extensions, such as two-way fixed effects models, group- or individual-specific effects, and post-treatment periods. Additionally, it includes functions for visualizing results, such as plotting DiD coefficients with confidence intervals and illustrating the temporal evolution of staggered treatments.
26
26
 
27
+ The diffindiff package is currently being extensively revised (v2.0.0 and following).
28
+
27
29
 
28
30
  ## Author
29
31
 
@@ -46,6 +48,7 @@ Thomas Wieland [ORCID](https://orcid.org/0000-0001-5168-9846) [EMail](mailto:geo
46
48
  - Including covariates
47
49
  - After-treatment period
48
50
  - Triple Difference (DDD)
51
+ - Multiple treatments
49
52
  - Own counterfactuals
50
53
  - **Visualization**: e.g.
51
54
  - Plot observed and expected time course of treatment and control group
@@ -3,6 +3,6 @@ pandas
3
3
  statsmodels
4
4
  matplotlib
5
5
  datetime
6
- sklearn
6
+ scikit-learn
7
7
  xgboost
8
8
  lightgbm
@@ -7,7 +7,7 @@ def read_README():
7
7
 
8
8
  setup(
9
9
  name='diffindiff',
10
- version='1.2.0',
10
+ version='1.2.2',
11
11
  description='diffindiff: Python library for convenient Difference-in-Differences Analyses',
12
12
  packages=find_packages(include=["diffindiff", "diffindiff.tests"]),
13
13
  include_package_data=True,
@@ -25,7 +25,7 @@ setup(
25
25
  'statsmodels',
26
26
  'matplotlib',
27
27
  'datetime',
28
- 'sklearn',
28
+ 'scikit-learn',
29
29
  'xgboost',
30
30
  'lightgbm'
31
31
  ],
File without changes
File without changes