version 10.0 capture log close log using chap09, replace use bangla, clear gen time = _n tsset time, yearly gen lp = log(p) gen la = log(a) regress la lp predict ehat, residual twoway (scatter ehat time) more * -------------------------------------------------- * Correlation between least sqaures residuals * -------------------------------------------------- gen ehat_1 = ehat[_n-1] correlate ehat ehat_1 * -------------------------------------------------- * regression with HAC standard errors * B is the computed bandwidth (which = 3) * -------------------------------------------------- scalar B = round(4*(e(N)/100)^(2/9)) scalar list B newey la lp, lag(3) * -------------------------------------------------- * Nonlinear least squares of AR(1) regression model * -------------------------------------------------- gen la_1 = L.la gen lp_1 = L.lp nl (la = {b1}*(1-{rho}) + {b2}*lp+ {rho}*la_1 - {rho}*{b2}*(lp_1)), variables(lp la la_1 lp_1) * -------------------------------------------------- * More general model * -------------------------------------------------- regress la lp L1.lp L1.la testnl _b[L1.lp]=-_b[L1.la]*_b[lp] * -------------------------------------------------- * Residual correlogram and graph * -------------------------------------------------- corrgram ehat ac ehat more drop ehat * -------------------------------------------------- * LM test * -------------------------------------------------- regress la lp estat bgodfrey * -------------------------------------------------- * Note: we set ehat(1) = 0 in order to match * result in text. In practice this is unnecessary. * -------------------------------------------------- predict ehat, residual replace ehat_1 = 0 in 1 regress ehat lp ehat_1 di (e(N))*e(r2) * -------------------------------------------------- * Autoregressive Model * -------------------------------------------------- use inflation, clear gen tt = ym(year,month) tsset tt, monthly regress infln L1.infln L2.infln L3.infln predict ehat, residuals scalar var = e(rmse)^2 ac ehat more * ------------------------------------------ * Long lines: change the delimiter to ; * ------------------------------------------ #delimit ; scalar yhat1 = _b[_cons]+_b[L1.infln]*infln[270]+ _b[L2.infln]*infln[269]+_b[L3.infln]*infln[268]; scalar yhat2 = _b[_cons]+_b[L1.infln]*yhat1+ _b[L2.infln]*infln[270]+_b[L3.infln]*infln[269]; scalar yhat3 = _b[_cons]+_b[L1.infln]*yhat2+ _b[L2.infln]*yhat1+_b[L3.infln]*infln[270]; scalar list yhat1 yhat2 yhat3; scalar se1 = sqrt(var); scalar se2 = sqrt(var*(1+(_b[L1.infln])^2)); scalar se3 = sqrt(var*((_b[L1.infln]^2+_b[L2.infln])^2+1+_b[L1.infln]^2)); scalar list se1 se2 se3; * Long lines over: restore the delimiter to cr; #delimit cr scalar f1L = yhat1 - 1.969*se1 scalar f1U = yhat1 + 1.969*se1 scalar f2L = yhat2 - 1.969*se2 scalar f2U = yhat2 + 1.969*se2 scalar f3L = yhat3 - 1.969*se3 scalar f3U = yhat3 + 1.969*se3 scalar list f1L f1U f2L f2U f3L f3U * -------------------------------------------------- * Distributed Lag Model * -------------------------------------------------- regress infln pcwage L1.pcwage L2.pcwage L3.pcwage predict ehat2, residual ac ehat2 more scalar IM0 = _b[pcwage] scalar IM1 = IM0 + _b[L1.pcwage] scalar IM2 = IM1 + _b[L2.pcwage] scalar IM3 = IM2 + _b[L3.pcwage] scalar list IM0 IM1 IM2 IM3 * -------------------------------------------------- * ARDL model * -------------------------------------------------- regress infln pcwage L1.pcwage L2.pcwage L3.pcwage L1.infln L2.infln predict ehat3, residual ac ehat3 more scalar b0 = _b[pcwage] scalar b1 = _b[L1.infln]*b0+_b[L1.pcwage] scalar b2 = _b[L1.infln]*b1+_b[L2.infln]*b0+_b[L2.pcwage] scalar b3 = _b[L1.infln]*b2+_b[L2.infln]*b1+_b[L3.pcwage] scalar b4 = _b[L1.infln]*b3+_b[L2.infln]*b2 scalar list b0 b1 b2 b3 b4 * -------------------------------------------------- * Appendix * Durbin Watson statistic * -------------------------------------------------- use bangla, clear gen lp = log(p) gen la = log(a) gen time = _n tsset time regress la lp estat dwatson * -------------------------------------------------- * Exponential Smoothing * -------------------------------------------------- use inflation, clear gen tt = ym(year,month) tsset tt, monthly tssmooth exponential sm1=infln, parms(.1) tssmooth exponential sm2=infln, parms(.2) twoway(tsline sm1 sm2 infln) log close translate chap09.smcl chap09.txt, replace