Python Forum
Tricky estimating three models and creating a table: regression
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tricky estimating three models and creating a table: regression
#1
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


# 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)
Reply
#2
Please post the entire error code (between the proper tags).
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a change table - £0.01-£0.50? MrKnd94 9 1,931 Oct-22-2022, 07:28 AM
Last Post: DPaul
  Issue with Dynamical Models course cilyt 1 2,626 Sep-13-2020, 09:40 AM
Last Post: ibreeden
  Advanced Algorithms and Computational Models hafedh 4 2,344 Aug-31-2020, 06:37 PM
Last Post: buran
  creating a 3x3 multiplication table aditvaddi 1 3,617 Jun-18-2018, 06:05 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020