*Time Series
version 14
clear
cap log close
cap program drop _all
cd "C:\Users\wasin\Desktop\BE_STATA_2"
log using timeseries.log,replace
************************************************************
* Read In Data 
* (Note: Change path name so that it is appropriate for your computer)
use macro_3e.dta
desc
tsset time
*************************
* transformations - US inflation, unemployment
*************************
gen lpunew = log(punew)
gen inf = 400*D.lpunew
gen dinf = D.inf
gen dinfa = 100*(lpunew[_n]-lpunew[_n-4])-100*(lpunew[_n-4]-lpunew[_n-8])
gen infpct = 400*((punew[_n]/punew[_n-1])-1)
gen dinfpct = D.infpct
gen dlhur = D.lhur
gen lhura = (lhur+L.lhur+L2.lhur+L3.lhur)/4
gen yq4 = (quarter(dofq(time))==4)
gen yr = year(dofq(time))-1900
* other examples
gen lgdpj = log(gdpjp)
gen dlgdpj = 400*D.lgdpj

*************************
*  Plots, tables, and autocorrelation
*************************
list time lhur punew infpct inf dinfpct
list time lhura dinfa
/*guaranteeing that data will be restored after program termination.
restore forces a restore of the data now.*/

preserve    
keep if tin(1960q1,2004q4)
* US inflation, unemployment rates
line inf  time
line lhur time


list time punew infpct L.infpct dinfpct if tin(2004q1,2005q1)

* correlations 
corrgram lhur if tin(1960q1,2004q4), noplot lags(8)
corrgram inf  if tin(1960q1,2004q4), noplot lags(8)
corrgram dinf if tin(1960q1,2004q4), noplot lags(8)


*************************
* Autoregessions
*************************
reg dinf L.dinf if tin(1962q1,2004q4)
dis "Rsquared = " _result(7)
* Robust Standard deviation 
reg dinf L.dinf if tin(1962q1,2004q4), r  
 dis "Rsquared = " _result(7)
 dis "Adjusted Rsquared = " _result(8)

reg dinf L(1/4).dinf if tin(1962q1,2004q4), r
 dis "Adjusted Rsquared = " _result(8)
 test L2.dinf L3.dinf L4.dinf

*************************
* Multiple regressions: empirical PCs
*************************
* Inflation-unemployment scatterplot (annual)
preserve
reg dinfa L4.lhur
predict pdinfa
keep if tin(1961q1,2004q4)
 graph7 dinfa pdinfa L4.lhur if yq4==1,
   xlab ylab s([yr].) c(.l) yline(0.) saving(f14_2e_3.gph,replace)
restore
*
reg dinf L(1/4).dinf L.lhur if tin(1962q1,2004q4), r
 dis "Adjusted Rsquared = " _result(8)
 test L2.dinf L3.dinf L4.dinf
*
reg dinf L(1/4).dinf L(1/4).lhur if tin(1962q1,2004q4), r
 dis "Adjusted Rsquared = " _result(8)
 test L2.dinf L3.dinf L4.dinf
 test L1.lhur L2.lhur L3.lhur L4.lhur
 test L2.lhur L3.lhur L4.lhur

*************************
* (a) Spurious regressions
*************************
reg  inf lgdpj if tin(1965q1,1981q4), r
 dis "Adjusted Rsquared = " _result(8)
reg  inf lgdpj if tin(1982q1,2004q4), r
 dis "Adjusted Rsquared = " _result(8)

*************************
* (b) Trends - DF test for inflation, unemployment
*************************
* inflation
reg dinf L.inf if tin(1962q1,2004q4)
reg dinf L.inf L(1/1).dinf if tin(1962q1,2004q4)
reg dinf L.inf L(1/2).dinf if tin(1962q1,2004q4)
reg dinf L.inf L(1/3).dinf if tin(1962q1,2004q4)
reg dinf L.inf L(1/4).dinf if tin(1962q1,2004q4)
reg dinf L.inf L(1/5).dinf if tin(1962q1,2004q4)
reg dinf L.inf L(1/6).dinf if tin(1962q1,2004q4)

log close


