Beispiel #1
0
with open('declarants_no_002_dict.pkl', 'r') as declarants:
    country_code = load(declarants)
declarants.closed

declarants = sorted(country_code.keys())

prices = ['p_2008', 'p_2009', 'p_2010', 'p_2011']
shares = ['s_2008', 's_2009', 's_2010', 's_2011']
cross = ['ps_2008', 'ps_2009', 'ps_2010', 'ps_2011']
cols = shares + prices + cross
start_time = datetime.now()

# Just testing for country = '001', column = 's_2008'
# for country in declarants:
country = '001'
reference_tuple = get_reference(yearly, country)
reference = reference_tuple[1]
    # for column in tb[shares]:
column = 's_2008'
# for product in tb['c_' + country][[column]].index.levels[0]:
product = '01'

refcountry = reference[product]
year = 'y' + column[-4:] + '_'
iyear = int(year[1:5] + '52')
prev = 'y' + str(int(year[1:5]) - 1) + '_'
iprev = int(prev[1:5] + '52')

ref_price = np.log(yearly[year + 'price_' + country].ix[1, iyear, product, refcountry].values)[0] - (
            np.log(yearly[prev + 'price_' + country].ix[1, iprev, product, refcountry].values)[0])
Beispiel #2
0
    l0 = []
    drops0 = []
    for product in gr0.groups.keys():
        try:
            l0.append((iyear0, product, ref_dict[product]))
        except KeyError:
            drops0.append(product)

    return pd.DataFrame((np.log(df1.ix[iyear1]) - np.log(df0.ix[iyear0]) - (
            np.log(df1.ix[l1].ix[iyear1].reset_index(level='PARTNER')['p' + str(year)].reindex(df1.index, level='PRODUCT_NC').ix[iyear1]) - (
            np.log(df0.ix[l0].ix[iyear0].reset_index(level='PARTNER')['p' + str(year - 1)].reindex(df0.index, level='PRODUCT_NC').ix[iyear0])))), columns=[name + str(year)]) ** square


for country in sorted(declarants):
    ref_dict = get_reference(yearly, country)
    for year in years[1:]:
        print 'Working on %r, %r.' % (country, year)
        print datetime.now() - start_time
        if year == 2008:
            gmm_store['country_' + country] = get_shares(country, year).merge(
                get_prices(country, year), how='outer', left_index=True, right_index=True).merge(
                get_shares(country, year, square=1, name=('c_' + str(year))) *
                get_prices(country, year, square=1, name=('c_' + str(year))),
                how='outer', left_index=True, right_index=True)
        else:
            gmm_store['country_' + country] = gmm_store['country_' + country].merge(
                get_shares(country, year), how='outer', left_index=True, right_index=True).merge(
                get_prices(country, year), how='outer', left_index=True, right_index=True).merge(
                get_shares(country, year, square=1, name=('c_' + str(year))) *
                get_prices(country, year, square=1, name=('c_' + str(year))),