Exemplo n.º 1
0
mean_std_observed_prices = df.groupby('t').rolling_std_upc.mean()[min_periods:]

#Mix Max scaling for xs
if use_logs_for_x:
    xs = np.log(df.groupby('firm').xs.first().values + 0.1)
else:
    xs = (df.groupby('firm').xs.first().values + 0.1)
scaler = MinMaxScaler()
xs = scaler.fit_transform(xs.reshape(-1, 1)).flatten()

Nfirms = len(xs)


#Draw shocks
#################
prior_shocks = src.gen_prior_shocks(Nfirms, σerror=0) # Add zeroes for the gmm estimation
taste_std_normal_shocks = np.random.normal(loc=0, scale=1, size=(max_t_periods_in_data, n_firms))
b0_std_normal_shocks = np.random.normal(loc=0, scale=1, size=n_firms)


# Optimization
##############################

all_firms = df.firm.unique()
firm_lengths_ = np.empty(len(all_firms) + 1, dtype=int)
firm_lengths_[0] = 0
for i, firm_i in enumerate(all_firms):
    firm_lengths_[i + 1] = df[df.firm == firm_i].index[-1] + 1


def error_w_data(θandΞres) -> float:
Exemplo n.º 2
0

#mean_std_observed_prices = df.groupby('t').std_dev_prices.mean()[min_periods:]
mean_std_observed_prices = df.groupby('t').rolling_std_upc.mean()[min_periods:]

#Mix Max scaling for xs
if use_logs_for_x:
    xs = np.log(df.groupby('firm').xs.first().values + 0.1)
else:
    xs = (df.groupby('firm').xs.first().values + 0.1)
scaler = MinMaxScaler()
xs = scaler.fit_transform(xs.reshape(-1, 1)).flatten()

Nfirms = len(xs)
# Just add zeroes. Makes sense for the gmm estimation
prior_shocks = src.gen_prior_shocks(Nfirms, σerror=0)


# Betas inertia procedure
@njit()
def new_generate_betas_inertia(firm_periods: int, i_firm: int) -> np.array:
    """
    Generates the vector of beta demands for a firm for a total of t periods
    given by the parameter firm_periods

    :param firm_periods:
    :param i_firm:
    :return:
    """
    betas = np.empty(firm_periods)
    betas[0] = b0[i_firm]