Modeling Time-Variation Over the Business Cycle (1960-2017): An International Perspective

Enrique Martinez-Garcia
Federal Reserve Bank of Dallas and SMU
emg.economics@gmail.com
Date: 7/8/2018


CODE IMPLEMENTATION (for Gauss 10)
----------------------------------
Based on the Gauss codes from Stock and Watson (2003):
Stock, James H. and Mark W. Watson (2003): Has the Business Cycle Changed and Why?, in NBER Macroeconomics Annual 
2002, Vol. 17, Mark Gertler and Kenneth Rogoff (eds.), MIT Press.


The code that needs to be run in Gauss for the program to work is ng_filt2.gss

For each new series, we need to make some small changes to adjust the code:

First, check that the code has the correct path to the data and for all the other auxiliary codes. 
The data should be in a sub-folder called Data within the same location and should include files 
with the extension *.qa60. The auxiliary codes to run this program are fcst.prc, udatain.prc and 
yulewalk.prc

Second, the code should indicate the data file and the type of transformation that you want to do to the data.
It would look like this:

let ylist[1,2] =  
test 1
;

where test is the name of the data file with extension qa60 that needs to be modified and where the number next 
to it indicates the transformation that we make to the data. The following options are available:

1 - is the series in levels (but expressed in percentages)
2 - first difference
3 - second difference
4 - logarithm of the series
5 - first difference of the logarithm
6 - second difference of the logarithm.

The code does not do seasonal adjustment, so the data needs to be seasonally adjusted before it is added to the file 
with extension qa60 (if that were needed).

Third, there are choices that we may want to modify at some point during the estimation. The critical ones appear here:

nfy=1960;                  @ First Year @
nfp=1;                     @ First Period of Year @
nly=2018;                  @ Last Year @
nlp=4;                     @ Last Period of Year @
nper=4;                    @ Number of Periods Per Year @
dpath="D:\\RESEARCH\\2017.INTERNATIONAL.BUSINESS.CYCLES\\Submission.Draft.(Globalization)_vFINAL\\FINAL_CODE.DATA\\Figure1_Stochastic.Volatility.Code\\FINAL\\Data\\";  @ Data Path @
missc=1.0e+032 ;           @ Missing Value Code in ASCII Files @
narlag=4;                  @ Number of AR lags @
tauvec=.05;                @ Regulates de mixture of probabilities
smplv = (1960.25~2017.75); @ Sample Period -- note obs prior to 1960 are not included @

where you can set the range of the sample and therefore determine how many observations to include, but also control 
the number of lags included in the estimation of the conditional mean process. The standard is to include four lags 
and 213 observations, but this can be changed according to the series at hand. tauvec regulates the mixture of 
probabilities used in the estimation as indicated in the papers of Stock and Watson (2003). I recommend not changing 
the parameter tauvec unless absolutely necessary.
NOTE: the path needs to be modified not just on those lines, but everywhere else in the code where it appears.

Finally, it is important to point out that the file with extension qa60 should include only the data but should also 
follow these conventions:

- the first row should be blank
- the last row should include 1.000000e+032 (at least one time, but it may be necessary to include it up to three times 
or four times because with quarterly data there may be several quarterly observations missing in the last year of the 
sample and without it the data points from the beginning would be added to complete the missing quarters).

After the code has completed its run, we can obtain the relevant output with the following two commands in the command 
window:

tmp    - this would give us the series transformed on which we have estimated the model which appears plotted together with 
the actual estimates of the standard deviation. This series indicates the transformation that arises from calculating the 
squared error between the actual data and the conditional mean (generally estimated with an AR(4) process) which describes 
the volatility of the error term relative to the conditional mean--it's a rough measure of the volatility. These series 
are reported in percentages.

smplv  - gives you the sample period defined for the data (just here for reference)

ydata  - gives you the actual data that is used for the estimation and it should correspond to the data in the qa60 extension 
         file before it has been transformed 

ytran  - should give you the data after the code has been partly transformed (as indicated before, the data can be estimated in levels, 
         first-differences, second-differences, etc. - at this stage of the transformation, we simply express the series in levels or 
	 log-levels and express it in percentages)

ytran2 - should give you the data after the code has finish transforming it (as indicated before, the data can be estimated in levels, 
         first-differences, second-differences, etc. - at this stage the data from ytran is unchanged if we choose to work with data in
	 levels or log-levels; otherwise, the next stage of the transformation involves calculating the appropriate first- or 
         second-difference of the partly-transformed series ytran)

stdann - this would give us the estimated STANDARD DEVIATION of the series (this is the instantaneous standard deviation 
         rather than the variance of the series): this instantaneous standard deviation is our measure of volatility 

NOTE: the data that I plot at the end of the sample and that I collect from the output of this code is tmp=abs(ytran2) and stdann
	 (expressed in percentages)