def startDriver(cmdopt): if not cmdopt == "": connectionParameters = { "key": cmdopt, "url": "https://apps.bea.gov/api/data/" } else: connectionParameters = {} dataBea = dpbea.data(connectionParameters) return (dataBea)
def test_startDriver(cmdopt): global dataBea if not cmdopt == "": connectionParameters = { "key": cmdopt, "url": "https://apps.bea.gov/api/data/" } else: connectionParameters = {} dataBea = dpbea.data(connectionParameters) assert dataBea return (dataBea)
10: 2, # 3 years of college 11: 3, # 4 years of college 12: 3 } # 5+ years of college # Load the ASEC CPS data CPS = pd.read_csv(os.path.join(CPSdata, 'CPSraw.csv'), header=0, usecols=columns, dtype=types) # Define a list of years years = CPS.YEAR.unique().tolist() # Load the NIPA personal income data from the BEA bea = dpb.data(BEAkey) personalincome = 1e6 * (bea.NIPA('T20100', frequency='A', year=years).iloc[2].values + bea.NIPA('T20100', frequency='A', year=years).iloc[8].values) \ / (1e3 * bea.NIPA('T20100', frequency='A', year=years).iloc[39].values \ * bea.NIPA('T10104', frequency='A', year=years).iloc[0].values / 1e2) # Recode the race variable CPS.loc[:, 'RACE'] = CPS.RACE.map(racemap) # Split the White and Black observations in each category second = CPS.loc[CPS.RACE == 12, :].copy(deep=True) second.loc[:, 'RACE'] = 2 second.loc[:, 'ASECWT'] = second.ASECWT / 2 CPS.loc[CPS.RACE == 12, 'RACE'] = 1 CPS.loc[CPS.RACE == 12, 'ASECWT'] = CPS.ASECWT / 2 CPS = CPS.append(second, ignore_index=True)
colors = [colormap(i) for i in np.linspace(0.3, 0.5,len(ax.lines))] for i,j in enumerate(ax.lines): j.set_color(colors[i]) ax.legend(fontsize = 10,loc=2) fig.text(0.04, 0.5, 'Time series of ' +plot_name, va='center', ha='center',rotation='vertical',fontsize = 14) plt.savefig("Time series of "+plot_name) plt.show() portfolio_plot(dfFactor[['Spread', 'RF']], 1, plot_name='Spread and RF' ,figsize=(8,4), cmap ='twilight') # #### For monthly time-series of labor income growth (BEA) # In[57]: BEA_data = dpb.data('FDA2D756-CC0A-4AAA-A1D5-980FA23F31BB') #or data = dpb.data("API Key") NIPA_cons=BEA_data.NIPA('T20600',frequency='M') #Download annual consumption data on nondurable goods from Table 2.6. #on “Personal Income and Its Disposition, Monthly” NIPA_cons.reset_index(inplace=True) Compensation_data=NIPA_cons[NIPA_cons['LineDescription']=='-Compensation of employees'] Compensation_data = Compensation_data.T.iloc[4:,:] Compensation_data.columns=['Compensation'] Compensation_data.index = pd.to_datetime(Compensation_data.index.values, format='%YM%m') Compensation_data['Income Growth'] = (Compensation_data['Compensation']-Compensation_data['Compensation'].shift(1))/Compensation_data['Compensation'].shift(1) # Convert strings to datetime Compensation_data = Compensation_data[(Compensation_data.index<=pd.to_datetime(edate)) & (Compensation_data.index>=pd.to_datetime(sdate))] Compensation_data['Mkt-RF'] = dfFactor['Mkt-RF']/100 Compensation_data['Income Growth'] = Compensation_data['Income Growth'] labor_market = (Compensation_data[['Income Growth','Mkt-RF']]+1).astype('f').resample('Y').prod()-1 portfolio_plot(labor_market, 1, plot_name='Income Growth and Mkt-RF (monthly)' ,figsize=(8,4), cmap ='twilight')