Skip to content

Commit

Permalink
v__0.160
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredgalichon committed Nov 23, 2024
1 parent 8245d76 commit a85a873
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
19 changes: 0 additions & 19 deletions mec/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions mec/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="mec",
version="0.159",
version="0.160",
authors=["Alfred Galichon"],
author_email="[email protected]",
licence="",
Expand Down

0 comments on commit a85a873

Please sign in to comment.