version 10.0 log using chap12, replace use usa, clear * --------------------------------------- * Create dates and declare time-series * --------------------------------------- gen qtr = mod(_n-1,4) + 1 egen year = seq(), f(1985) t(2005) b(4) gen date = yq(year,qtr) format %tq date tsset date * --------------------------------------- * Create dates and declare time-series * the easier way * --------------------------------------- drop date gen date = q(1985q1) + _n - 1 format %tq date tsset date * --------------------------------------- * Graph time-series * Graphs are saved and combined. * To rerun this do file: * 1) rename graphs * 2) delete graphs in saved location * 3) delete the saving() commands * --------------------------------------- twoway(tsline gdp), saving(gdp) twoway(tsline D.gdp), saving(dgdp) graph combine gdp.gph dgdp.gph more * --------------------------------------- * graph interest rates * note: twoway is implied and can be omitted * More saved graphs. See note above. * --------------------------------------- tsline inf, saving(inf) tsline D.inf, saving(dinf) tsline F, saving(f) tsline D.F, saving(df) tsline B, saving(b) tsline D.B, saving(db) graph combine gdp.gph dgdp.gph inf.gph dinf.gph, saving(graph1) more graph combine f.gph df.gph b.gph db.gph, saving(graph2) more * --------------------------------------- * Summary Statistics for subsamples * --------------------------------------- summarize if date<=q(1994q4) summarize if date>=q(1995q1) & date<=q(2004q4) * --------------------------------------- * Spurious Regression * --------------------------------------- use spurious, clear gen time = _n tsset time regress rw1 rw2 tsline rw1 rw2 more scatter rw1 rw2 more * --------------------------------------- * Unit root tests and cointegration * --------------------------------------- use usa, clear gen date = q(1985q1) + _n - 1 format %tq date tsset date * Augmented Dickey Fuller Regressions regress D.F L1.F L1.D.F regress D.B L1.B L1.D.B * Augmented Dickey Fuller Regressions with built in functions dfuller F, regress lags(1) dfuller B, regress lags(1) * ADF on differences dfuller D.F, noconstant lags(0) dfuller D.B, noconstant lags(0) * Engle Granger cointegrations test regress B F predict ehat, residual regress D.ehat L.ehat L.D.ehat, noconstant * Using the built-in Stata commands dfuller ehat, noconstant lags(1) log close translate chap12.smcl chap12.txt, replace