Oct-18-2017, 02:36 PM
I'm fairly new to Python, so I don't know how to upload the working file, but I have done a lot of regressions, plots and graphs before this part, but everything is working fine. (however there might be something causing this, Idunno). I have a table of dft, with 6 columns, for all the variables before this part. But on this part I keep getting error messages: KeyError: ('const', 'cpr_t3m') - along with many other
I think the last part is ok, but from estimating ols and up is the problem
Any suggestions to what is causing this? or What I can do? The lecturer said this question was straightforward, but I am having difficulties!
Thanks for all the help, in advance! :D
I think the last part is ok, but from estimating ols and up is the problem
Any suggestions to what is causing this? or What I can do? The lecturer said this question was straightforward, but I am having difficulties!
Thanks for all the help, in advance! :D
# Homework question is: Now consider three alternative models # Δgdp = β0 + β1 ∗cpr_t3m + ϵt # Δgdp = β0 + β1 ∗cpr_t3m + β2 * Δgdp(t-1) + ϵt # Δgdp = β0 + β1 ∗cpr_t3m + β2 * Δgdp(t-1) + β3 * cpr_t3m(t-1) + ϵt # Estimate these three models and present them in a table. (Hint: use the table format from the QuantEcon site I showed in class) #Making new variables for change in gdp(t-1) and t3m(t-1) dft["gdp_dt"] = (dft['cpr_realgdp']/dft['cpr_realgdp'].shift(2)) dft["cpr_t3m_t"] = (dft['cpr_t3m']/dft['cpr_t3m'].shift(1)) dft['const'] = 1 dft = dft.dropna(subset=['cpr_t3m', 'gdp_d1', 'cpr_t3m_t', 'gdp_dt']) # Create lists of variables to be used in each regression, not sure why this is not running X1 = dft['const', 'cpr_t3m'] X2 = dft['const', 'cpr_t3m', 'gdp_dt'] X3 = dft['const', 'cpr_t3m', 'gdp_dt', dft['cpr_t3m_t']] # Estimate an OLS regression for each set of variables reg11 = sm.OLS(dft['gdp_d1'], dft[X1], missing='drop').fit() reg22 = sm.OLS(dft['gdp_d1'], dft[X2], missing='drop').fit() reg33 = sm.OLS(dft['gdp_d1'], dft[X3], missing='drop').fit() from statsmodels.iolib.summary2 import summary_col info_dict={'R-squared' : lambda x: "{:.2f}".format(x.rsquared), 'No. observations' : lambda x: "{0:d}".format(int(x.nobs))} results_table = summary_col(results=[reg11,reg22,reg33], float_format='%0.2f', stars = True, model_names=['Model 1', 'Model 2', 'Model 3'], info_dict=info_dict, regressor_order=['gdp_d1', 'cpr_t3m', 'gdp_d1'.shift(1), 'cpr_t3m'.shift(1)]) results_table.add_title('Table 2 - OLS Regressions') print(results_table)