From 3b07e440fbe10d065fdd4447b07619abac598f42 Mon Sep 17 00:00:00 2001 From: Alfred Galichon Date: Tue, 17 Dec 2024 07:42:08 +0100 Subject: [PATCH] v__0.191 --- mec/mx.py | 36 ++++++++++++++++++------------------ setup.py | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/mec/mx.py b/mec/mx.py index 066a28b..a1fd559 100644 --- a/mec/mx.py +++ b/mec/mx.py @@ -24,21 +24,21 @@ def efficient_ivgmm(Y_i,X_i_k,Z_i_l, centering = True): return beta2_k,val2 -def iv_gmm(Y_i,X_i_k,Z_i_l, efficient=False, centering = True): - def beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l=None ): - ZtildeT_k_i = (X_i_k.T @ Z_i_l @ Z_i_l.T) if W_l_l is None else (X_i_k.T @ Z_i_l @ W_l_l @ Z_i_l.T) - return np.linalg.solve(ZtildeT_k_i @ X_i_k,ZtildeT_k_i @ Y_i) - I=len(Y_i) - W_l_l = np.linalg.inv( Z_i_l.T @ Z_i_l / I) - beta_k = beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l ) # first stage obtained by 2SLS - if efficient: - epsilon_i = Y_i - X_i_k @ beta_k - mhat_l_i = Z_i_l.T * epsilon_i[None,:] - mbar_l = mhat_l_i.mean(axis=1) - Sigmahat_l_l = (mhat_l_i @ mhat_l_i.T) / I - centering * mbar_l[:,None] * mbar_l[None,:] - W_l_l = np.linalg.inv(Sigmahat_l_l) - beta_k = beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l ) - Pi_i_i = Z_i_l @ W_l_l @ Z_i_l.T - XPiY_k_i = X_i_k.T @ Pi_i_i @ Y_i - objval = (Y_i.T @ Pi_i_i @ Y_i - XPiY_k_i.T @ np.linalg.inv( X_i_k.T @ Pi_i_i @ X_i_k ) @ XPiY_k_i )/ (2*I*I) - return beta_k,objval +# def iv_gmm(Y_i,X_i_k,Z_i_l, efficient=False, centering = True): +# def beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l=None ): +# ZtildeT_k_i = (X_i_k.T @ Z_i_l @ Z_i_l.T) if W_l_l is None else (X_i_k.T @ Z_i_l @ W_l_l @ Z_i_l.T) +# return np.linalg.solve(ZtildeT_k_i @ X_i_k,ZtildeT_k_i @ Y_i) +# I=len(Y_i) +# W_l_l = np.linalg.inv( Z_i_l.T @ Z_i_l / I) +# beta_k = beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l ) # first stage obtained by 2SLS +# if efficient: +# epsilon_i = Y_i - X_i_k @ beta_k +# mhat_l_i = Z_i_l.T * epsilon_i[None,:] +# mbar_l = mhat_l_i.mean(axis=1) +# Sigmahat_l_l = (mhat_l_i @ mhat_l_i.T) / I - centering * mbar_l[:,None] * mbar_l[None,:] +# W_l_l = np.linalg.inv(Sigmahat_l_l) +# beta_k = beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l ) +# Pi_i_i = Z_i_l @ W_l_l @ Z_i_l.T +# XPiY_k_i = X_i_k.T @ Pi_i_i @ Y_i +# objval = (Y_i.T @ Pi_i_i @ Y_i - XPiY_k_i.T @ np.linalg.inv( X_i_k.T @ Pi_i_i @ X_i_k ) @ XPiY_k_i )/ (2*I*I) +# return beta_k,objval diff --git a/setup.py b/setup.py index 49d21bc..e7f38c5 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="mec", - version="0.190", + version="0.191", authors=["Alfred Galichon"], author_email="ag133@nyu.edu", licence="",