py-did-multiplegt-dyn 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Anzony Quispe, Clement de Chaisemartin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: py_did_multiplegt_dyn
3
+ Version: 0.1.3
4
+ Summary: Estimation of event-study Difference-in-Difference (DID) estimators in designs with multiple groups and periods, and with a potentially non-binary treatment that may increase or decrease multiple times.
5
+ Author-email: Anzony Quispe <anzony.quispe@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/anzonyquispe/py_did_multiplegt_dyn
8
+ Project-URL: Issues, https://github.com/anzonyquispe/py_did_multiplegt_dyn/issues
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.txt
12
+ Requires-Dist: numpy>=1.24
13
+ Requires-Dist: pandas>=2.0
14
+ Requires-Dist: scipy>=1.10
15
+ Requires-Dist: polars>=1.3.0
16
+ Requires-Dist: statsmodels>=0.12.5
17
+ Dynamic: license-file
18
+
19
+ # py_did_multiplegt_dyn
20
+ This is the python version of the main Stata package did_multiplegt_dyn.
@@ -0,0 +1,2 @@
1
+ # py_did_multiplegt_dyn
2
+ This is the python version of the main Stata package did_multiplegt_dyn.
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "py_did_multiplegt_dyn" # name on PyPI
7
+ version = "0.1.3"
8
+ description = "Estimation of event-study Difference-in-Difference (DID) estimators in designs with multiple groups and periods, and with a potentially non-binary treatment that may increase or decrease multiple times."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "MIT" } # or "BSD-3-Clause", etc.
12
+ authors = [
13
+ { name = "Anzony Quispe", email = "anzony.quispe@gmail.com" },
14
+ ]
15
+ dependencies = [
16
+ "numpy>=1.24",
17
+ "pandas>=2.0",
18
+ "scipy>=1.10",
19
+ "polars>=1.3.0",
20
+ "statsmodels>=0.12.5",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/anzonyquispe/py_did_multiplegt_dyn"
25
+ Issues = "https://github.com/anzonyquispe/py_did_multiplegt_dyn/issues"
26
+
27
+ [tool.setuptools]
28
+ package-dir = {"" = "src"}
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,45 @@
1
+ import numpy as np
2
+
3
+ def gaussian_elimination(A, b, tol=1e-7, verbose=False):
4
+ """Perform Gaussian elimination on augmented matrix [A|b]."""
5
+ A = A.astype(float).copy()
6
+ b = b.astype(float).copy()
7
+ m, n = A.shape
8
+ Ab = np.hstack([A, b])
9
+
10
+ for i in range(min(m, n)):
11
+ # Pivot
12
+ max_row = np.argmax(np.abs(Ab[i:, i])) + i
13
+ if abs(Ab[max_row, i]) < tol:
14
+ continue
15
+ if max_row != i:
16
+ Ab[[i, max_row]] = Ab[[max_row, i]]
17
+
18
+ # Normalize pivot row
19
+ Ab[i] = Ab[i] / Ab[i, i]
20
+
21
+ # Eliminate other rows
22
+ for j in range(m):
23
+ if j != i:
24
+ Ab[j] -= Ab[j, i] * Ab[i]
25
+
26
+ return Ab
27
+
28
+ def Ginv(A, tol=np.sqrt(np.finfo(float).eps), verbose=False):
29
+ """Generalized inverse using Gaussian elimination (R's Ginv)."""
30
+ A = np.asarray(A, dtype=float)
31
+ m, n = A.shape
32
+
33
+ # First elimination
34
+ B = gaussian_elimination(A, np.eye(m), tol=tol, verbose=verbose)
35
+ L = B[:, n:] # columns after first n
36
+ AR = B[:, :n] # first n columns
37
+
38
+ # Second elimination
39
+ C = gaussian_elimination(AR.T, np.eye(n), tol=tol, verbose=verbose)
40
+ R = C[:, m:].T # columns after first m, then transpose
41
+ AC = C[:, :m].T # first m columns, then transpose
42
+
43
+ # Construct generalized inverse
44
+ ginv = R @ AC.T @ L
45
+ return ginv