From a85a87382393d2f3f00636f0c80e6a03001062d4 Mon Sep 17 00:00:00 2001 From: Alfred Galichon Date: Sat, 23 Nov 2024 22:09:04 +0100 Subject: [PATCH] v__0.160 --- mec/data.py | 19 ------------------- mec/mx.py | 19 +++++++++++++++++++ setup.py | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mec/data.py b/mec/data.py index 668fc4a..7906455 100644 --- a/mec/data.py +++ b/mec/data.py @@ -109,25 +109,6 @@ def getcleandata(name,nrow): import numpy as np, pandas as pd -def create_blp_instruments(X, mkts_firms_prods,include_ones = False): - if include_ones: - X = np.block([[np.ones((X.shape[0],1)), X ]] ) - df = pd.DataFrame() - names = [str(i) for i in range(X.shape[1])] - df[ names ]=X - df[['mkt','firm','prod']] = mkts_firms_prods - thelist1, thelist2 = [], [] - for _, theserie in df[ names ].items(): - thelist1.append ([theserie[(df['mkt']==df['mkt'][i]) & - (df['firm']==df['firm'][i]) & - (df['prod']!=df['prod'][i]) ].sum() for i,_ in df.iterrows() ]) - - thelist2.append([theserie[(df['mkt']==df['mkt'][i]) & - (df['firm']!=df['firm'][i]) ].sum() for i,_ in df.iterrows() ]) - - return np.array(thelist1+thelist2).T - - def load_blp_data(pyblp_compatibility=True): """ Returns the data used by Berry, Levinsohn and Pakes (2005) diff --git a/mec/mx.py b/mec/mx.py index c82b243..5d64188 100644 --- a/mec/mx.py +++ b/mec/mx.py @@ -24,6 +24,25 @@ def beta_gmm(Y_i,X_i_k,Z_i_l,W_l_l ): return beta_k,objval +def create_blp_instruments(X, mkts_firms_prods,include_ones = False): + if include_ones: + X = np.block([[np.ones((X.shape[0],1)), X ]] ) + df = pd.DataFrame() + names = [str(i) for i in range(X.shape[1])] + df[ names ]=X + df[['mkt','firm','prod']] = mkts_firms_prods + thelist1, thelist2 = [], [] + for _, theserie in df[ names ].items(): + thelist1.append ([theserie[(df['mkt']==df['mkt'][i]) & + (df['firm']==df['firm'][i]) & + (df['prod']!=df['prod'][i]) ].sum() for i,_ in df.iterrows() ]) + + thelist2.append([theserie[(df['mkt']==df['mkt'][i]) & + (df['firm']!=df['firm'][i]) ].sum() for i,_ in df.iterrows() ]) + + return np.array(thelist1+thelist2).T + + def pi_inv(pi_t_y,theLambda_k_k,epsilon_t_i_k, xi_k_y,maxit = 100000, reltol=1E-8, require_grad =False): (K ,Y ) = xi_k_y.shape (T,I,_) = epsilon_t_i_k.shape diff --git a/setup.py b/setup.py index 99b697e..81f9e58 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="mec", - version="0.159", + version="0.160", authors=["Alfred Galichon"], author_email="ag133@nyu.edu", licence="",