Estimating a Dynamic Factor Model in EViews Using the Kalman Filter and Smoother

Dynamic factor models have become very popular for analyzing high-dimensional time series, and are now standard tools in, for instance, business cycle analysis and forecasting. Despite their popularity, most statistical software do not provide these models within standard packages. We briefly review the literature and show how to estimate a dynamic factor model in EViews. A subroutine that estimates the model is provided. In a simulation study, the precision of the estimated factors are evaluated, and in an empirical example, the usefulness of the model is illustrated.


Introduction
Dynamic factor models are used in data-rich environments.The basic idea is to separate a possibly large number of observable time series into two independent and unobservable, yet estimable, components: a 'common component' that captures the main bulk of co-movement between the observable series, and an 'idiosyncratic component' that captures any remaining individual movement.The common component is assumed to be driven by a few common factors, thereby reducing the dimension of the system.
In Economics, dynamic factor models are motivated by theory, which predicts that macroeconomic shocks should be pervasive and affect most variables within an economic system.They have therefore become popular among macroeconometricians; see, e.g., Breitung and Eickmeier (2006), for an overview.Areas of economic analysis using dynamic factor models include, for example, yield curve modeling (e.g., Diebold and Li 2006;Diebold et al. 2006), financial risk-return analysis (Ludvigson and Ng 2007), monetary policy analysis (e.g., Bernanke et al. 2005;Boivin et al. 2009), business cycle analysis (e.g., Forni and Reichlin 1998;Eickmeier 2007;Ritschl et al. 2016), forecasting (e.g., Stock and Watson 2002a, b) and nowcasting the state of the economy, that is, forecasting of the very recent past, the present, or the very near future of indicators for economic activity, such as the gross domestic product (GDP) (see, e.g., Banbura et al. 2012, and references therein).Information of the economic activity is of great importance for decision makers in, for instance, governments, central banks and financial markets.However, first official estimates of GDP are published with a significant delay, usually about 6-8 weeks after the reference quarter, which makes nowcasting very useful.Despite the attractiveness of dynamic factor models for macroeconomists, statistical or econometric software do not in general provide these models within standard packages.In this paper, we illustrate how to, by means of programming, set up the popular two-step estimator of Doz et al. (2011) in EViews (IHS Global Inc. 2015a, b, c, d), a software specialized in time series analysis that is broadly used by economists, econometricians, and statisticians.
The parameters of dynamic factor models can be estimated by the method of principal components.This method is easy to compute, and is consistent under quite general assumptions as long as both the cross-section and time dimension grow large.It suffers, however, from a large drawback: the data set must be balanced, where the start and end points of the sample are the same across all observable time series.In practice, data are often released at different dates.A popular approach is therefore to cast the dynamic factor model in a state space representation and then estimate it using the Kalman filter, which allows unbalanced data sets and offers the possibility to smooth missing values.The state space representation contains a signal equation, which links observed series to latent states, and a state equation, which describes how the states evolve over time.Under the assumption of Gaussian noise, the Kalman filter and smoother provide mean-square optimal projections for both the signal and state equations.The method we set up in this paper is a two-step procedure, in which parameters are first estimated by principal components, and then, given these estimates, the factors are re-estimated as latent states by the Kalman smoother.
The rest of the paper is organized as follows.Section 2 outlines the notion and conventional estimation of dynamic factor models.Section 3 derives a state space solution.Section 4 describes the estimator considered in this paper.The estimator is evaluated in a simulation study in Sect.5, and applied in an empirical example in Sect.6. Section 7 concludes.A subroutine containing the estimator and programs that replicate our results are provided as supplementary material.

A Dynamic Factor Model
Let x t = (x 1,t , x 2,t , . . ., x N ,t ) be a vector of N time series, each of which is a realvalued stochastic process {x i,t , t ∈ Z}.Suppose we observe a finite realization of x t over some time points t = 1, 2, . . ., T , and let the empirical information available at time t be condensed into the information set F t = {x 1 , x 2 , . . ., x t }.A dynamic factor model is usually specified such that each observable x i,t (i = 1, 2, . . ., N ) is the sum of two independent and unobservable components: a common component χ i,t , which is driven by a small number of factors that are common to all individuals, and a remaining idiosyncratic (individual-specific) component i,t (see, e.g., Bai and Ng 2008).In panel notation, the model is where ) is a vector lag-polynomial of constants loading onto a vector of K unobservable common factors, z t = (z 1,t , z 2,t , . . ., z K,t ) .1 Thus, only the left-hand side of (1) is observed; the righthand side is unobserved.If the dimension of z t is finite (K < ∞), then there exists for every i an Forni et al. 2009 ).2 Thus, letting , the dynamic factor model can be cast in the static representation (2) which, equivalently, can be written in vector notation as where . The common factors in z t are often referred to as dynamic factors, while the common factors in f t are referred to as static factors.The number of static factors, R, cannot be smaller than the number of dynamic factors, and is typically much smaller than the number of cross-sectional individuals, K ≤ R N .As with χ i,t in the dynamic representation (1), we refer to the scalar process c i in (2), or the multivariate process c t in (3), as the common component.
In general, we suppose that x i,t is a weakly stationary process with mean zero that has finite second-order moments, E(x i,t ) = 0, E(x i,t x i,t−s ) < ∞ (s ∈ Z).To uphold this, something close to the following is usually assumed: A1 (common factors) The q-variate process z t is independent and identically distributed (i.i.d.) over both the cross-section and time dimension with zero mean: where ω 2 j < ∞ for all j.A2 (idiosyncratic components) The process i,t admits a Wold representation . white noise with limited cross-sectional dependence: E(u i,t ) = 0, E(u i,t u j,s ) = 0 for all t = s, and E(u i,t u j,t ) = τ i, j , with N i=0 |τ i, j | < J , where J is some positive number that does not depend on N or T .A3 (independence) The idiosyncratic errors u t = (u i,t , u 2,t , . . ., u N ,t ) and common shocks z t are mutually independent groups: E(u t z s ) = 0 for all t, s.
From Assumption A1, the static factors are stationary and variance-ergodic processes admitting a Wold representation Assuming invertibility, the static factors may therefore follow some stationary VAR( p) process, where We have assumed here, for the sake of argument, that the dynamic factors z t (sometimes referred to as the primitive shocks) enters as errors in the static factor VAR process (4).This is unnecessarily strict.To be more precise, by suitably defining f t , the dynamic factor model (1) can in general be cast in the static representation (2), where f t follows a VAR process which exact order depends on the specific dynamics of z t .The number of static factors is always R = K( + 1), where K is the number of dynamic factors and is the order of the vector lag-polynomial υ i (L) in the common component in (1); see Bai and Ng (2007).In practice, the static representation is typically stated without reference to a more general dynamic factor model.Additionally, it is often assumed that the static common factors follow a stationary VAR process.Assumption A1 is innocuous, as we may assume that z t is an orthonormal error of the static factor VAR process, and that this, in general, relates to some dynamic factor model (1).Now, from Assumptions A1-A3, the autocovariance of the panel data is where 0), we can write the contemporary covariance matrix of x t as = ϒ + .If the largest eigenvalue of is bounded as N → ∞, then we have an approximate factor model as defined by Chamberlain and Rothschild (1983).Approximate factor models have become very popular within, for instance, panel data econometrics, because they allow for a cross-sectional dependence among t , whilst letting the factor structure be identified.If is diagonal, then we have the exact (or strict) factor model.Since the diagonal elements of are real and finite, the exact factor model is nested within the approximate factor model as a special case.The largest eigenvalue of is, in fact, smaller than max j N i=1 |E( i,t j,t )| (see Bai 2003), which is bounded with respect to both N and T by Assumption A2. 3 Hence, by assumption, we have an approximate factor model.
On top of this, some technical requirements are usually placed on the factor loadings, such that the common component is pervasive as the number of cross-sectional individuals increase.In essence, as N → ∞, all eigenvalues of N −1 should be positive and finite, implying that the R largest eigenvalues of are unbounded asymptotically. 4Because the largest eigenvalue of is asymptotically bounded, the covariance decomposition in is asymptotically identifiable.
Note finally that, without imposing restrictions, the factors and factor loadings are only identified up to pre-multiplication with an arbitrary R × R full rank matrix M. That is, (3) is observationally equivalent to x t = ˇ ft + t where ˇ = M and ft = M −1 f t , since, in terms of variances, = ϒ + = ˇ V ar( ft ) ˇ + .Due to this rotational indeterminacy in the factor space, we may without loss of generality impose the normalization ϒ = I R , restricting M to be an orthogonal matrix.This implies that only the spaces spanned by, respectively, the columns of and those of f t , are identifiable from the contemporary covariance .In general, this identification requires a large N .In many cases, estimating the space spanned by the factors is as good as estimating the factors themselves.For instance, in forecasting under squared error loss, the object of interest is the conditional mean, which is unaffected by rotational multiplication.If, however, the actual factors or the coefficients associated with the factors are the parameters of interest, then we need to impose some identifying, yet arbitrary, restrictions such that the factors and factor loadings are exactly identified; see Bai and Ng (2013) and Bai and Wang (2014).

Estimation
Estimation of dynamic factor models concern foremost the common component; the idiosyncratic component is generally considered residual.The common component of the dynamic factor model (1) may be consistently estimated in the frequency domain by spectral analysis (see, e.g., Forni et al. 2004).The main benefit of the static represen- 4 To be more precise, Doz et al. (2011) Because the eigenvalues of N −1 are non-zero, the eigenvalues of are unbounded as N → ∞.
tation (3), however, is that for an approximate factor model, the common component may be consistently estimated in the time domain, which computational methods are generally much easier to accomplish.Because the factor model is a panel (i.e., x i,t is doubly indexed over dimensions N and T ), asymptotic theory has been developed as both dimensions N and T tend to infinity, which requires some special attention.Conceptually, estimation theory for panels can be derived in three ways: sequentially, diagonally, and jointly (see, e.g., Phillips and Moon 1999;Bai 2003).The methods presented in this paper all concern the latter limit.This limit is the most general, and its existence implies the existence of the other two limits.
From Assumption A2, each idiosyncratic component is a stationary and varianceergodic process that, assuming invertibility, may be stated as a finite-order autoregressive process, φ i (L) i,t = u i,t , where φ i (L) = θ i (L) −1 , so that the idiosyncratic process in (3) may be written as (L) t = u t , where u t = (u 1,t , u 2,t , . . ., u N ,t ) and (L) = diag(φ 1 (L), φ 2 (L), . . ., φ N (L)).In terms of parameters, the static factor model (3) may then be characterized by The autocovariances f (h) and (h) for h = 0 are rarely of direct interest, and are not necessary for consistent estimation of the common component c t .In most cases, we are merely interested in { , ϒ, }, since is, up to a rotation, asymptotically identifiable from (that depends on f (0) = ϒ and (0) = ).Given these parameters, the minimum mean square error (minimum MSE) predictor of the static factors is the projection (see, e.g., Anderson 2003, Sect. 14.7) where ϒ = I R , under conventional normalization (see aforementioned).Naturally, the parameters and are unknown, and need to be estimated.On theoretical grounds, maximum likelihood (ML) estimation is attractive.It is generally efficient and provides means for incorporating restrictions based on theory.However, ML estimators for dynamic factor models tend to be very complicated to derive, and full ML estimation is only available for special cases (see, e.g., Stoica and Jansson 2009;Doz et al. 2012).When the idiosyncratic component exhibits either time series dynamics, cross-sectional heteroscedasticity, or cross-sectional correlations, then full ML estimation is not attainable.However, by imposing misspecifying restrictions, subsets of the parameters may be consistently estimated by quasi-ML in the sense of White (1982).For example, by falsely assuming an exact factor model when the true model is an approximate factor model, the diagonal elements of (i.e., the contemporary idiosyncratic variances) and the space spanned by the columns of may be consistently estimated by numerical quasi-ML estimation based on the iterative Expectation-Maximization (EM) algorithm; see Bai andLi (2012, 2016).In a similar fashion, Doz et al. (2012) have shown that the space spanned by the factors may be directly and consistently estimated by quasi-ML using the Kalman filter.If the procedure is iterated, then it is equivalent to the EM algorithm.
The workhorse for the static factor model is the method of principal components (PC).Consider the covariance matrix of x t , .Because every covariance matrix is positive semi-definite, it may be decomposed as = V V , where = diag(ϕ 1 ( ), ϕ 2 ( ), . . ., ϕ N ( )) is a diagonal matrix with the ordered positive eigenvalues of (the principle components) on its main diagonal, and V is a matrix with the associated eigenvectors as columns, such that V V = I N .Under the normalization ϒ = I R , the linear transformation m t = V x t is the population PC estimator of the factors f t .It has contemporary covariance V ar(m t ) = V V = .Because is a diagonal matrix, the population factors are uncorrelated.Now, let The first PC factor, f1,t = v 1 x t , is the projection which maximizes the variance among all linear projections from unit vectors.Its variance is the first principal component ϕ 1 ( ).The second PC factor, f2,t = v 2 x t , maximizes the variance under the restriction of being orthogonal to the first PC factor.Its variance is the second principle component ϕ 2 ( ), and so on.The PC estimator of the factor loadings is found be setting ˆ equal to the eigenvectors of associated with its R largest eigenvalues.Replacing with its sample counterpart S = T −1 T t=1 x t x t , gives the sample PC estimators.Under an approximate factor model, they are consistent as N , T → ∞ (i.e., as N and T tend to infinity simultaneously) for the spaces spanned by the factors and factor loadings, respectively; see, foremost, Stock and Watson (2002a) and Bai (2003).
The method of PC is a dimension reducing technique, and does, as opposed to ML, not require the existence of the static factor model ( 3).Yet, the PC and ML estimators are closely related.Under a Gaussian static factor model with spherical noise, the ML estimator of the factors is proportional to the PC estimator.The PC estimators of the factors and factor loadings are therefore often used as initial estimators for ML algorithms.For approximate factor models, the largest drawbacks of the PC estimators are that (i) they are inconsistent for fixed N , and (ii) they require a balanced panel.Meanwhile, ML estimation can be consistent for fixed N , and numerical procedures, such as the Kalman filter and the EM algorithm can smooth over missing values, allowing an unbalanced panel with missing values at the end or start of the panel; the so called "ragged edge" or "jagged edge" problem.This feature is very valuable in, for instance, economic forecasting, because key economic indicators tend to be released at different dates.In particular, and of special interest in this paper, Doz et al. (2011) show that, by consistently estimating B(L), the precision in estimating the factor space may be improved by setting up a state space solution and perform one run with the Kalman smoother to re-estimate the factors f t for t = 1, 2, . . ., T .This method is presented in detail in Sect.4, and can be implemented in EViews by using our code in the supplementary material.
For any estimation approach, the number of factors R is generally unknown, and needs to be either estimated or assumed.Popular estimators for the number of factors in approximate factor models can be found in Bai and Ng (2002), Onatski (2010) and Ahn and Horenstein (2013).Throughout the paper, we will treat the number of factors as known.

A State Space Representation of the Static Factor Model
The linear time series process x t can be cast in the state space form where α t (k × 1) is a latent state vector, H t (N × k) and T t (k × k) are possibly timevarying parameter matrices and R t (k × q; q ≤ k) is, in general, either the identity matrix or a selection matrix consisting of a subset of the columns of the identity matrix (see, e.g., Durbin and Koopman 2012).The system is stochastic through the N × 1 vector ξ t and the k × 1 vector η t , which are mutually and serially uncorrelated with zero mean and contemporary covariance matrices ξ and η , respectively.In the Gaussian state space form, which is what EViews handles, the errors are normally distributed: ξ t ∼ N (0, ξ ), η t ∼ N (0, η ).We refer to (6) as the signal equation, and to (7) as the state equation.Note that the state equation is a VAR(1) process.
The static factor model (3) can be written as a state space solution defined by ( 6) and ( 7), where the number of states relates to the latent components of the model, that is, the common factors and the idiosyncratic components.Moreover, as shown by Doz et al. (2011), neglecting the idiosyncratic time series dynamics, and thereby possibly misspecifying the underlying model, can still lead to consistent estimation of the central parameters of the factor model, given by the common component.Specifically, imposing the misspecification that t in (3) is white noise, the static factor model can be written in state space form where the number of states k is equal to the number of factors R times the number of VAR lags p: k = R p.To see this, note that the factor VAR( p) process (4) can be written in stacked form as the VAR(1) process (see, e.g., Lütkepohl 2007, p. 15) where Thus, if the static factors follow the VAR process (4) and the idiosyncratic components are serially uncorrelated, then the static factor model (3) has a state space representation defined by ( 6) and ( 7) with where and t are the factor loadings and idiosyncratic error in (3), ft and B are the stacked factors and parameters in (9) and z t is the error in (4).Here, the subscripts may be dropped from H t , T t and R t , since in this case, the parameters are not time-varying.Specification and estimation of state space models in EViews is outlined in IHS Global Inc. (2015d, Chapter 39).A recent demonstration is found in van den Bossche (2011).The estimation concerns two aspects: (i) measuring the unknown states α t for t = 1, 2, . . ., T , involving prediction, filtering and smoothing (see Sect. 3.1), and (ii) estimation of the unknown parameters H t , T t , ξ and η .Doz et al. (2011) propose to estimate the parameters by PC (see Sect. 2.1), and leave only the estimation of the factors (i.e., the states) to the state space form (see Sect. 4).
Remark 3.1 The Eq. ( 7) is specified for the states in period t + 1, given the errors in period t, which requires some consideration when modeling correlations between the signal and state errors in EViews.However, by Assumption A3, the state and signal errors are mutually uncorrelated.Therefore, the construction of the temporal indices of the state and signal equations do not affect the methods we use in this paper.For a state space specification with contemporary error indices, see, e.g., Hamilton (1994, p. 372).

The Kalman Filter and Smoother
The latent state vector α t can be estimated numerically by the Kalman filter and smoother (see, e.g., Harvey 1989; Durbin and Koopman 2012, for thorough treatments).Consider the conditional distribution of α t , based on the available information at time t − 1, F t−1 .Under the Gaussian state space model, the distribution is normal α t |F t−1 ∼ N (a t|t−1 , P t|t−1 ), where By construction, a t|t−1 is the minimum MSE estimator of (the Gaussian) α t , with MSE matrix P t|t−1 .Given the conditional mean, we can find the minimum MSE estimator of x t from (6), with error v t = x t − xt and associated N × N error covariance matrix where ξ was defined in relation to (6).
The Kalman filter is a recursion over t = 1, 2, . . ., T that, based on the error v t and the dispersion matrix F t , sequentially updates the means and variances in the conditional distributions α t |F t ∼ N (a t|t , P t|t ) and α t+1 |F t ∼ N (a t+1|t , P t+1|t ) by where T t and η were defined in relation to (7).The computational complexity of the recursion depends largely on the inversion of F t .Note that the second term in (11) may be viewed as a correction term, based on the last observed error v t .EViews refers to a t|t as the filtered estimate of α t , and to a t+1|t as the one-step ahead prediction of α t .The recursion requires the initial one-step ahead predicted values a 1|0 and its associated covariance matrix P 1|0 .If x t is a stationary process, then they can be found analytically.
Otherwise, EViews uses diffuse priors, following Koopman et al. (1999).The user may also provide the initial conditions; see van den Bossche (2011) and IHS Global Inc. (2015d, p. 683).Additionally, we need estimates of the parameters H t , T t , ξ and η.
Conveniently, the Kalman filter provides the likelihood function as a by-product from the one-step ahead prediction errors (see Harvey 1989, Sect. 3.4.),and the recursion can therefore be based on maximum likelihood estimators of the parameters; EViews offers various numerical optimization routines to find the associated estimates.In this paper, however, we follow Doz et al. (2011) and estimate the main parameters of the dynamic factor model (3) by PC; only the factors are estimated using the Kalman filter.This method is consistent and generally much faster than a recursion that includes parameter estimation.The Kalman filter is a forward recursion.By applying a backward (smoothing) recursion using the output from the Kalman filter, we can find a t|T , the F T -conditional (i.e., conditional on all available observations) minimum MSE estimator of α t , and its associated MSE matrix P t|T .There are different kinds of smoothing algorithms (see, e.g., Durbin and Koopman 2012, Sect. 4.4).EViews uses a fixed-interval smoothing, which in its classical form returns the estimated means and variances of the conditional distributions α t |F T ∼ N (a t|T , P t|T ) by Because the smoothed estimator a t|T is based on all observations, its MSE cannot be larger than the MSE from the filtered estimator a t|t , in the sense that the MSE matrix of the latter is the MSE matrix of the smoothed estimator plus some positive definite matrix. 5he Kalman filter and smoother offer an exceptionally easy way of handling missing values, whereby the matrix H t is simply set to zero (see, e.g., Durbin and Koopman 2012, Sect. 4.1).This treatment preserves optimality.Similarly, MSE-optimal forecasts are conducted by treating future values of x t as missing observations.4 The Two-Step Estimator of the Common Factors Doz et al. (2011) show that misspecifying the static factor model (3) with respect to some of the dynamics and cross-sectional properties may still lead to consistent estimation of the space spanned by the common factors.They propose to estimate the common factors in two steps.In the first step, preliminary parameter estimates are computed by PC.In the second step, the factors are re-estimated by MSE-optimal linear projection from one run of the Kalman smoother, allowing for idiosyncratic cross-sectional heteroscedasticity, common factor dynamics, as well as an unbalanced panel.
Because the factors and factor loadings are not uniquely identified, Doz et al. ( 2011) consider a specific rotation, outlined in the following way.Under the normalization ϒ = I R , we have that = + , so that is identified up to an orthogonal multiplication (see Sect. 2).Let have spectral decomposition = QDQ , where D = diag(ϕ 1 ( ), . . ., ϕ R ( )) and QQ = I N , and consider the following representation of the factor model (3): where + = Q and g t = Q f t .By construction, + + = D and + + = , such that there exists a matrix P = + D −1/2 with the property P P = I R .Because f t has a VAR representation (4), g t also has a VAR representation, where B + (L) = Q B(L)Q and w t = Q z t .In many cases, estimating g t , or any other rotation of f t , is as good as estimating f t itself (see Sect. 2).In particular, the conditional mean, which is used when forecasting under squared error loss, is unaffected by the rotation.Suppose X = (x 1 , x 2 , . . ., x T ) is the N × T matrix of standardized and balanced panel data with sample covariance matrix S = T −1 T t=1 x t x t = T −1 XX .Let D = diag(d 1 , d 2 , . . ., d R ) be a diagonal matrix with the R largest eigenvalues of S on its main diagonal, and let P be the R × R matrix with the associated eigenvectors as columns.Under the specific rotation Q f t , the PC estimators of the factors and factor loadings (see Sect.  , ψ N ,N ) is a diagonal matrix with the diagonal elements of on its main diagonal.The parameters of the the approximating models Ω A3 and Ω A4 can be consistently estimated even though the true model is characterized by Ω.Moreover, given the parameters, the precision in the factors can be improved by linear projection using the Kalman filter based on the state space solution in Sect.3.
Here, imposing the rotation g t = Q f t , implies that g t by assumption follows the VAR representation (12).Hence, for the state space solution in Sect.3, {g t , B + 1 , . . ., B + p , w t , + } replace {f t , B 1 , . . ., B p , z t , } in the representation (10).The signal and state equations ( 6) and ( 7) are then, respectively, As shown by Doz et al. (2011), the following steps provide a consistent method for estimating the factors under Ω A3 and Ω A4 : 1. Estimate + and g t for t = 1, 2, . . ., T by the rotated PC estimators ( 13) and ( 14). 2. Estimate the VAR polynomial B + (L) by the ordinary least squares (OLS) regression Under standard aforementioned assumptions it holds as N , T → ∞ that B+ m , for m = 1, 2, . . ., p.
3. Run the Kalman smoother over the state space model defined by ( 15) and ( 16) to re-estimate the factors g t for t = 1, 2, . . ., T , conditional on the estimates ˆ + and B+ (L).
To apply the Kalman filter we need to know the covariance matrices ξ and η (see Sect. 3), which here correspond to, respectively, the idiosyncratic covariance matrix and the covariance matrix for w t in (12), V ar(w t ).Under Assumptions A1-A3, S p → , as N , T → ∞.Thus, we may consistently estimate by ˆ = S− ˆ + ˆ + p → − + + = − = .Similarly, a consistent estimator of V ar(w t ) may be based on the residuals in ( 17).
The model defined by Ω A4 is the most general of the two approximating models, and is therefore expected to have the highest precision in estimating the factors, unless the model defined by Ω A3 is in fact the true (or very close to the true) model.

Implementing the Two-Step Estimator in EViews
In the supplementary material, we provide the file subroutine_dfm containing a subroutine named DFM that estimates the approximating models characterized by Ω A3 and Ω A4 .To call the subroutine, either the subroutine code should be placed directly into a user's main script, or the file subroutine_dfm should be included using the command Include; see Chapter 6 in IHS Global Inc. (2015a).
EViews works around objects, consisting of information related to a specific choice of analysis.Two types of objects are frequently used when programming in EViews: string objects (i.e., sequences of characters) and scalar objects (i.e., numbers).However, in the code we make more extensive use of the related concepts string variables and control variables, which are temporary variables whose values are strings and scalars, respectively, and that only exist while the EViews program executes.String variables have names that begin with a "%" (see IHS Global Inc. 2015a, p. 92).Control variables have names that begin with a "!" (see IHS Global Inc. 2015a, p. 126).For example, the commands %ser = "gdp" and !n = 5 create a string variable %ser containing the characters 'gdp' and a control variable !n containing the number 5. By enclosing these variables in curly brackets, "{" and "}", EViews will replace the expressions with the underlying variable value (see section on replacement variables in IHS Global Inc. 2015a, p. 130).For example, the commands series {%ser} and Group G{!n} create a series object named gdp and a group object named G5.
The subroutine DFM is defined by DFM(Group XGrp, Scalar FNum, Scalar VLag, Sample S, String Model) where each argument is specified by an EViews object: a group object XGrp containing the observable time series in x t , a scalar object FNum containing the number of factors, a scalar object VLag containing the number of lags in the factor VAR representation (12), a sample object S over which the Kalman smoother should estimate the states, and a string object Model that should be set to "A3" for the model characterized by Within the subroutine, XGrp is assigned the series in the group G, FNum is assigned the number 2, VLag is assigned the number 1, S is assigned the sample J, and Model is assigned the characters 'A4'.The objects within the subroutine are global, meaning that any changes to the objects inside the subroutine will change the very objects or variables that are passed into the subroutine.For instance, in the subroutine, the series in XGrp are standardized prior to the PC estimation.Hence, this will standardize the series in the group that is used to call the subroutine (G, in the example).EViews offers also the possibility to use local subroutines; see IHS Global Inc. (2015a, p. 156).
Table 1 displays a summary of the objects that are stored in the Eviews workfile.These objects belong to the state space specification of the dynamic factor model, implying that they are required to produce certain output, such as state series graphs, and state or signal forecasts (see IHS Global Inc. 2015d, Chapter 39).Note that once the subroutine is called, the objects will be written over.Thus, if the subroutine is called several times in an active workfile, say in a loop, then only the objects from the last run will be available, unless they are consecutively stored by the user.
The subroutine executes the steps 1-3 as outlined above. 6First, the data are standardized over the balanced panel, and the factors and factor loadings are estimated by ( 13) and ( 14).7 Next, we estimate the factor VAR (17), producing the matrix BHat (see Table 1).By default, BHat is the R p × R matrix ( B(1) , B(2) , . . ., B(R) ) , where B( j) is a containing the jth columns of each of the estimated autoregressive coefficient matrices B+ k (k = 1, 2, . . ., p) from the regression (17).That is, the first row of BHat is the first column of B+ 1 , the second row is the first column of B+ 2 , and so on.For more details, see IHS Global Inc. (2015b, p. 815). 8astly we set up a state space object and run the Kalman smoother.For the state space object we need to declare signal and state properties (see van den Bossche 2011), where every line in ( 15) and ( 16) has to be specified.Moreover, if an error should exist for a specific equation line, then it must be specified.In the signal equation ( 15), all lines should have errors, whereas in the state equation ( 16), only the first R lines should have errors (relating to the elements in w t ).These errors are named by the keyword @ename.The signal errors are named e1, e2, and so on, and the state errors are named w1, w2, and so on.
The error variances and covariances are specified using the keyword @evar.Variances and covariances that are not specified are by default zero.Following the estimation procedure for the models defined by Ω A4 and Ω A3 , the signal errors are, by misspecification, uncorrelated over both time and the cross-section.As such, we are only concerned with the contemporary signal error variances (the diagonal elements of , that also correspond to the diagonal elements of ξ in Sect.3).For the model Ω A4 , these parameters are assigned the PC-estimated variances ψ1,1 , ψ2,2 , . . ., ψN,N , collected in the diagonal of CovEpsHat (see Table 1).For the model Ω A3 , we impose the restriction = ψI N , where, following Doz et al. (2011), ψ is estimated by the mean of the estimated idiosyncratic variances, ψ = N −1 N i=1 ψi,i = N −1 trace( ˆ ).The state errors relate to the factor VAR residuals, and are, under correct specification, also white noise.The variances and covariances of the R first state errors are assigned the elements in the residual covariance matrix from the estimated regression (17), CovWHat (see Table 1).
After declaring the signal and state error properties, the subroutine DFM defines and appends the signal and state equations to the state space object DFMSS using the keywords @signal and @state.The output of main interest are the estimated factors.The subroutine lets SVk_m refer to factor k, lag m.Thus, we are primarily interested in SV1_0, SV2_0, …, SVR_0, i.e., the states referring the contemporary factors.The remaining states, SV1_1, SV2_1, …, SVR_p, refer to lags of the factors, and are simply created for the sole reason to complete the markovian state space solution for the Kalman filter and smoother (see Sect. 4).Accordingly, the state space object allows only one-period lags of the states.

Remark 4.1
We have assumed that the number of factors R is known.In practice, this is rarely the case.We could of course estimate the number of factors (see references in Sect.2.1); though, forecasting or nowcasting (see Sect. 6), the appropriate number of factors is rather a practical concern, and can be found from forecasting evaluations.The same reasoning applies to the number of lags in the factor VAR regression (17).
In case we wish to estimate the number of lags, however, we may use the criteria available in EViews; see IHS Global Inc. (2015b, p. 838) andIHS Global Inc. (2015d, Sect. 38).These criteria are also discussed in Lütkepohl (2007, Sect. 4.3).
Remark 4.2 Forecasts can be made for the signal and state equations using the EViews built-in procedures; see IHS Global Inc. (2015d), p. 676.Because future values are treated as missing data by the Kalman smoother, smoothed state forecasts can be carried out by simply extending the sample to include the forecast period.

Monte Carlo Simulation
For consistency, we replicate the parts of the simulation study by Doz et al. (2011) that compares the precision of the models defined by Ω A4 and Ω A3 .Code that reproduces the simulation study is available in the supplementary material.Doz et al. (2011) consider a one-factor (R = 1) setup with the following data generating process (DGP): where U denotes the uniform distribution.That is, the factor and idiosyncratic components are AR(1) processes, f t = b f t−1 +z t , i,t = φ i,t−1 +u i,t (i.e., the idiosyncratic AR-coefficients are the same over the cross-section), where the idiosyncratic components are possibly cross-sectionally dependent through the covariance matrix u .The constant δ controls for the amount of idiosyncratic cross-correlation, where δ = 0 implies the exact factor model with no cross-sectional dependence.The constant β i controls the signal-to-noise ratio, i.e., the ratio between the variance of x i,t and the variance of the idiosyncratic component i,t .For this constant we have used the wellknown result that a uniformly distributed variable in the interval [m l , m u ] may be generated as m l + (m u − m l )μ, where μ ∼ U(0, 1).The correlated idiosyncratic errors are generated using a Cholesky decomposition, u = LL , where L is a lower diagonal matrix.The multivariate normal error u t ∼ N (0, u ) is then generated as Le t , where e t ∼ N (0, I N ), for t = 1, 2, . . ., T .
The autoregressive coefficients are set to b = 0.9 and φ = 0.5, and the constants δ and m are set to δ = 0.5 and m = 0.1.Note that the variances of the errors z t and u i,t are so that the variances of f t and i,t are 1 and κ i , respectively.9For a coherent DGP, the starting values for the factors and idiosyncratic components, f 0 and i,0 , should come from the stationary distributions of f t and i,t , respectively.By construction of the DGP, we have that f t ∼ N (0, 1) and i,t ∼ N (0, κ i ), for all t.Hence, f 0 and i,0 should also be N (0, 1) and N (0, κ i ), respectively.For convenience, we generate T + 1 observations for periods t = 0, 1, 2, . . ., T and discard the starting values x i,0 .
The dimensions are N = 5, 10, 25, 50, 100 and T = 50, 100.The panel is unbalanced between the time points T − 3 and T by letting x i,t be available for t = 1, 2, . . ., T − j if i ≤ ( j + 1) N 5 .That is, at time T − 3, 80% of the data are available; at time T − 2, 60% are available; at time T − 1, 40% are available; and at time T , 20% are available.For each set of dimensions {N , T }, the parameters β i and λ i are drawn 50 times.Then, for each such draw, the error processes z t and u t are generated 50 times.Hence, the total number of replications is 2500.At each replication, we execute steps 1-3 from Sect. 4 using our subroutine.To evaluate the precision of the smoothed factors ĝt , the following measure is used: where Q is the estimated coefficient from an OLS regression of f t on ĝt , using the sample between t = 1 and t where Ĝ = (ĝ 1 , ĝ2 , . . ., ĝT −4 ) and F = (f 1 , f 2 , . . ., f T −4 ) .A value closer to zero indicates higher squared error precision (see Doz et al. 2011).Because f t is in this particular study a univariate process, we have that In the simulation study we run a large number of replications.This increases the probability that the OLS estimator of the VAR coefficients in (17) by chance may provide estimates that are inconsistent with a stationary VAR.That is to say, whereas we use a single factor with true parameter b = 0.9, the estimate of b may occasionally be 1 or larger.To avoid these cases (they are very rare), we assign such estimates with a value that is near the boundary of the stationary parameter space (a value close to 1, from below).
Table 2 shows a replication of the parts of Table 1 in Doz et al. (2011) that are related to models Ω A4 and Ω A3 .Here, Δ A4 T −s and Δ A3 T −s denote the evaluation by (20) of a smoothed factor in period T − s (s = 0, 1, . . ., 4) from models Ω A4 and Ω A3 , respectively, and ΔA4 T −s and ΔA3 T −s denote their averages over the 2500 replications.The panel is unbalanced for s = 0, 1, 2, 3.The upper part of Table 2 displays the averages ΔA4 T −s , and the lower part displays the ratios ΔA4 T −s / ΔA3 T −s (a value below 1 indicates that Ω A4 is, on average, more accurate).Our simulation results are close to the results in Doz et al. (2011).However, we note that we have somewhat higher precision for small N , while slightly less precision for large N .As expected, the average precision of Ω A4 is uniformly better than the average precision of Ω A3 . in parameter estimation.Therefore, a dynamic factor model is a natural choice of model, as an efficient dimension reducing technique.Furthermore, while collinearity is generally bad for conventional estimation methods, such as OLS, collinearity is rather preferred when extracting factors, since the goal for the extracted factors is to cover the bulk of variation in the elements of x t .As can be seen in Table 3, all 124 indicators would be available within 5-6 weeks after the last day of the reference quarter.This is 2-3 weeks before the first outcome of GDP is released.We could also choose to nowcast the GDP growth well before this date; either by smoothing missing data or by simply removing all data with later publication dates.A nowcast for y t may be found by first estimating the monthly factors f j,t for j = 1, 2, . . ., R, using the two-step estimator outlined in Sect.4, and then by regressing the GDP growth on the quarterly (collapsed) factors, where α and β j are estimated regression parameters, and f Q j,t are quarterly averages of the monthly factors f j,t . 10We could also consider lagging the quarterly factors.However, as advocated by Giannone et al. (2008), the contemporary factors should capture the bulk of dynamic interaction among the indicators, and hopefully also the bulk of dynamics in GDP growth. 11 We deflate export and import of goods using their respective price indices.The deflated series are then seasonally adjusted using the U.S. Census Bureau's x12-ARIMA procedure, accessible from EViews (see IHS Global Inc. 2015c, p. 416).Likewise, we seasonally adjust and replace all price indices and new registrations of cars.Lastly, before estimating the dynamic factor model, we make the transformations outlined in Table 3 to achieve stationarity.The series that we use from the Economic Tendency Survey are measured in net balances; they are therefore stationary (or approximately stationary) by construction (see, e.g., Hansson et al. 2005; Österholm 2014, for descriptions of the survey).Based on the (now) stationary monthly indicators, we estimate two monthly factors (R = 2) that follow a VAR(2) over the sample 2002M01-2017M06.For seven of the monthly indicators, the start date is later than 2002M01.For these series, we let the Kalman filter smooth the missing values.
There are numerous outputs and tools available for analyzing a state space object in EViews; see van den Bossche (2011) andIHS Global Inc. (2015d, Chapter 39).Here, our main interest is in the estimated factors and their associated error bounds.As discussed in Sect.3.1, EViews allows the user to create filtered states, one-step ahead 10 Another approach is to let (a monthly) y t be a part of the observed vector so that x t = (y t , x 1,t , . . ., x N ,t ) (see, e.g., Schumacher and Breitung 2008;Banbura and Runstler 2011).At point t, y t is missing.By projection from the Kalman filter or the EM algorithm, the minimum mean-square error estimator of y t can be achieved. 11Naturally, we could use the same principle to make a forecast of y t+h , for some h > 0 (see, e.g., Stock and Watson 2002a, b).The main difference between forecasting and nowcasting is that, for nowcasting we exploit contemporary (rather than leading) indicators.For forecasting, Stock and Watson (2002b) suggest to use lags of both the factors and y t as predictors.predictions of states or smoothed states.In the subroutine, we use smoothed states (see Sect. 4.1).By default, EViews provides uncertainty bounds constructed from 2 standard errors (see Fig. 1).Recall from Sect.4.1 that there are R p = 2 × 2 = 4 states, where the first two (SV1_0 and SV2_0) are our estimated factors, and the last two are their lags.In our case, the estimated uncertainty in terms of standard errors is somewhat larger for the second factor than for the first.
Given the estimated factors (that cover the nowcast period), the estimated regression (21) and its nowcast can easily be obtained in EViews using the interface menus (see IHS Global Inc. 2015c, Chapter 2), or by programming (see IHS Global Inc. 2015a, pp. 360-362).Carrying out the regression, our nowcast for the GDP growth 2017Q2 is 1.29 percent; the first published outcome by mid-September 2017 was 1.27 percent.Naturally, it would be desirable to have the associated error bounds for the nowcast.However, basing the error bounds on theory is a bit more cumbersome than usual, since the regressors in (21) (i.e., the factors) are estimated, and not observed series (see Bai and Ng 2006).EViews provides conventional error bounds based on a regression (see IHS Global Inc. 2015d, p. 144).In this particular case, they would be too narrow.Moreover, the error bounds are complicated by GDP revisions, where the most recent quarterly outcomes tend to also be revised, affecting the current growth rate.Figure 2 shows the quarterly collapsed factors and the GDP growth nowcast for 2017Q2 (including outcome up to 2017Q1).Judging from the figure, it is tempting to conclude that the second factor is partly lagging the first factor.However, its movement is rather a consequence of being (almost) orthogonal to the first factor.

Concluding Remarks
We have demonstrated how to estimate a dynamic factor model by the Kalman filter and smoother in EViews and provided a global subroutine that can be useful to a broad range of economists or statisticians using large panel data to extract dynamic factors.Because the estimation requires only to compute principal components and then make one run with the Kalman smoother, the procedure is fast.Several extensions are possible.For instance, the code can be used to make an EViews Add-in.The code could also easily be altered to meet specific user needs.For example, a user may find it more convenient to work with a local subroutine.Or a user may wish to add estimation procedures for the number of factors and the number of lags in the factor autoregression.These modifications would require only basic knowledge in the EViews programming language.

→
the covariance decomposition in is identifiable (see Sect. 2), then under Assumptions A1-A3 in Sect. 2 it holds that ĝt p → g t and ˆ + p → + , as N , T → ∞, where 123 p denotes convergence in probability.The PC estimators are thus consistent, and in that sense they suffice.They do not, however, exploit the factor time series dynamics imposed by B(L), or the fact that the idiosyncratic components are potentially cross-sectionally heteroscedastic (i.e., that the diagonal elements of are possibly different).Also, they require a balanced panel.Conveniently, the Kalman filter offers a solution to these issues.Suppose that the true model (3) fulfills Assumptions A1-A3.Let this model be characterized by Ω = { , B(L), (L), }.Doz et al. (2011) consider two misspecifications of Ω where the Kalman smoother can be used to exploit the dynamics of the common factors composed in B(L): one model that is characterized by Ω A3 = { , B(L), I N , ψI N }, where ψ is a constant, and a second model that is characterized by Ω A4 = { , B(L), I N , d }, where d = diag(ψ 1,1 , . . .

Fig. 1
Fig. 1 Smoothed monthly state estimates (black solid lines) with error bounds (gray dashed lines)

Fig. 2
Fig. 2 GDP growth nowcast and quarterly factors

Table 1
Summary of objects that are stored by the subroutine DFM

Ω
A3, or to "A4" for the model characterized by Ω A4 .The subroutine is called by the keyword Call.Suppose, for example, that we want to estimate a dynamic factor model under Ω A4 using two factors that are VAR(1).If there is a time series group object G and a sample object J, then the subroutine may be called by