Data and replication files for "Principal Component Analysis for Nonstationary Series" by James D. Hamilton and Jin Xi
   *.m are Matlab programs and *.rpf are RATS programs

cyclical factors
   Data and code in this directory calculate the cyclical components of a set of variables and calculate their principal components

     create_yX.m creates the explanatory variables to form h-period-ahead forecasting regression
     lsq.m performs ordinary least squares
     fhat.m performs principal component analysis
     application_yields.m analyzes interest rates in the dataset Yield2022.xlsx
     application_FREDMD_new.m analyzes the FREDMD datasets of vintages 2014-04.csv, 2024-12.csv, or other vintage

macro indexes
   Data in this directory report the indexes created from running application_FREDMD_new.m

     individual_components_2015.xls Cyclical components of individual variables in the 2015-04.csv database
     individual_components_2024.xls Cyclical components of individual variables in the 2024-12.csv database
     macro_factors_2015.csv Cyclical macro factors in the 2015-04.csv database
     macro_factors_2023.csv Cyclical macro factors in the 2024-12.csv database
    

MN_replicate
   Data and code in this directory use the McCracken-Ng algorithm to calculate indexes on various subsamples

     main_replicate.m is the code to run to calculate McCracken-Ng output

RATS
  This directory contains RATS code to generate the figures used to describe the FRED-MD data

      graph_select_series.rpf plots graphs of individual series
      graph_factors.rpf plots graphs of aggregate indexes

forecasts
  This directory contains Matlab code to calculate R2 and evaluate forecasts

     generate_yvar Code in this directory creates yvar_2015.mat or yvar_2024.mat, which assemble data in Matlab structures for use in forecasting
     Rsquared.m calculates R2 explained by factors for individual variables in the 2022-04.csv database
     compare_forecasts.m calculates the forecast summaries in Table 1


      

    



