Stata Code for Money-Income Example

/*Typing Between Stars makes it a Comment*/

/*Delimit Command Tells Stata that Each Command ends with a Semicolon*/

# delimit ;

/*Set more off tells Stata to Print All Output at Once*/

set more off;
clear;

/*Referencing Dataset*/

use C:\Users\pshea\Mon_In.dta ;

/*Telling Stata to Overwrite log file*/

log using C:\Users\pshea\Mon_In.log,replace;

/*Telling Stata which is the time series indicator*/

tsset date;

/*Taking some logs*/

gen ip_log=ln(ip);

gen cpi_log=ln(cpi);

/*Taking some lags*/

gen cpi_lag1=cpi_log[_n-1];

gen ip_lag1=ip_log[_n-1];

gen ffr_lag1=ffr[_n-1];

/*Collecting descriptive statistics*/

summarize ip cpi ffr, detail;

/*Calculating the correlation matrix (includes autocorrelations)*/

correlate ip cpi ffr ip_lag1 cpi_lag1 ffr_lag1;

/*Running a regression*/

reg ip_log cpi_log ffr;

/*Now adding the Unit Root tests to the code*/

/*Creating some first differences*/

gen d1ip_log = ip_log-ip_lag1;

gen d1ffr= ffr-ffr_lag1;

gen d1cpi_log= cpi_log-cpi_lag1;

gen d1cpi_lag1=d1cpi_log[_n-1];

gen d2cpi_log= d1cpi_log-d1cpi_lag1;

/*Choosing lag length for DF test on IP*/

dfgls ip_log;

/*Conducting DF test for IP_log*/

dfuller ip_log, lag(2) trend;

/*testing for Unit Root on First Difefrence of IP_log*/

dfgls d1ip_log;

dfuller d1ip_log, lag(2) trend;

/*Checking for Non-stationarity of federal Funds Rate*/

dfgls ffr;

dfuller ffr, lag(13) trend;

dfgls d1ffr;

dfuller d1ffr, lag(12) trend;

/*Checking for Non-stationarity of CPI*/

dfgls cpi_log;

dfuller cpi_log, lag(12) trend;

dfgls d1cpi_log;

dfuller d1cpi_log, lag(11) trend;

/*Re-running regression based on first differences*/

reg d1ip_log d1cpi_log d1ffr;

estat ic;

reg d1ip_log d1cpi_log;

estat ic;

/*VAR time*/

var d1cpi_log d1ffr d1ip_log, lag(1);

irf create order1, step(10) set(C:\Users\pshea\irf1,replace);

irf graph oirf, impulse(d1ffr d1cpi_log d1ip_log) response(d1ffr d1cpi_log d1ip_log);

varsoc d1cpi_log d1ffr d1ip_log;

var d1cpi_log d1ffr d1ip_log, lag(1,2);

irf create order2, step(10) set(C:\Users\pshea\irf2,replace);

irf graph oirf, impulse(d1ffr d1cpi_log d1ip_log) response(d1ffr d1cpi_log d1ip_log);

fcast compute for, step(20) bs;

fcast graph ford1ip_log ford1cpi_log ford1ffr;

/*Alternate Order*/

varsoc d1ip_log d1ffr d1cpi_log;

var d1ip_log d1ffr d1cpi_log, lag(1,2);

irf create order3, step(10) set(C:\Users\pshea\irf3,replace);

irf graph oirf, impulse(d1ffr d1cpi_log d1ip_log) response(d1ffr d1cpi_log d1ip_log);

fcast compute for2, step(20) bs;

fcast graph for2d1ip_log for2d1cpi_log for2d1ffr;

/*Vector Error Correction Model*/

vecrank d1cpi_log d1ffr d1ip_log;

vec d1cpi_log d1ffr d1ip_log, lags(2) rank(2);

irf create order4, step(10) set(C:\Users\pshea\irf4,replace);

irf graph oirf, impulse(d1ffr d1cpi_log d1ip_log) response(d1ffr d1cpi_log d1ip_log);

fcast compute for3, step(20);

fcast graph for3d1ip_log for3d1cpi_log for3d1ffr;