Matlab utilities for time series (and other) data developed in collaboration the the BCC
Download the code as a ZIP file by clicking the green 'Clone or download' button and selecting 'Download ZIP'.
These utilities perform basic functions like processing data and estimating simple models, including OLS models, vector autoregressions, and unrestricted MIDAS models for monthly/quarterly mixed frequency data. Examples are included in the sample_scripts folder. All functions work with base Matlab, however, seasonal adjustment requires the (free) X-13 toolbox.
[A] = comp_form(B)Put the matrix B in companion form[Xf, Xp, T] = detrend(Y, varargin)Remove low frequency trends and outliers from data YFEVD = fevd(irf)Calculate forecast error variance decomposition[ind] = finite_index(X)Find the indexes of rows containing only finite values[smoothed] = fLOESS(noisy,span)Loess function by Gabriel Marsh[irf] = IRF(B, Q, horz, chol_id, unit_var)Calculate impulse response functions (IRFs)[irf, irf_upper, irf_lower] = IRF_local(X, lags, horz, ridge, chol_id, unit_var)Calculate locally estimated IRFs (i.e. local projection)[beta, sigma, sd_beta, t_val, sig_beta] = OLS(X,Y, varargin)Estimate an OLS model[beta, sigma, sd_beta, t_val, sig_beta] = OLS_HAC(X,Y, varargin)Heteroskedasticity and autocorrelation consistent OLS estimation[Xf, Xp, Tnd, X_saf, X_level, X_scale, X_center] = process(Xtable, lib)Process timeseries data to insure stationaritystatus = run_R_script(script_path, args)Run an R script from Matlab[X, x_mean, x_scale] = scale(X)Scale and center data[X,Y] = sim_MIDAS(T)Simulate MIDAS data to test the functionUMIDAS()[X,Y] = sim_OLS(T, B, q)Simulate OLS data to test the functionOLS()X = sim_VAR(T, B, Q)Simulate VAR data to test the functionVAR()[zz] = stack_obs(z,p, drop_last)Stack observations in VAR or DFM format[fit, err, B, RHS, lhs, Time, sigma, sig_beta, t_val] = UMIDAS(yf, Xf, lags, ridge, include_months, intercept, verbose)Simple unrestricted MIDAS estimation for monthly/quarterly mixed frequency data[X_sa, X_nsa] = unprocess(Xtimetable, lib, X_level, Tnd, X_saf, X_scale, X_center)Undo processing from theprocess()function[B, Sig, Sig_B, fit] = VAR(X, lags, varargin)Estimate a vector autoregression (VAR)
MATLAB is required to run the code. The code was tested in MATLAB R2015b and later versions. Functionality with earlier versions of MATLAB is not guaranteed.