R

  • An Introduction to Factor-Augmented Vector Autoregression (FAVAR)

    Introduction

    As we saw in the post on vector autoregressive (VAR) models, traditional VAR models suffer from a so-called curse of dimensionality. Each additional variable adds a further equation and a further lag polynomial to every other equation, so the number of coefficients grows with the square of the number of variables. With the few decades of quarterly data that are usually available this limits a VAR to a handful of variables. Policy makers, however, base their decisions on a much larger set of indicators than a VAR can accommodate, and leaving that information out of the model can distort the results.

  • How Long Will Services Inflation in Austria Stay High?

    Services inflation in Austria has been stubborn. Energy and food prices have long stopped rising at the pace of 2022, but services, which make up half of the Austrian consumer basket, are still getting more expensive by more than 4% a year. Hochmuth and Petz (2026) offer an explanation for the euro area: before the pandemic, services became steadily more expensive relative to goods, the surge of goods prices in 2021 and 2022 pushed this relative price far below its trend, and part of today’s services inflation is services prices catching up. Their error correction model says how fast that happens.

    This post applies their model to Austria. The reproduction of the paper covers the euro area in detail, and its results serve as the benchmark here. The short answer is that the explanation does not carry over: in Austria the relative price of services has already returned to its trend and gone beyond it. A closer look shows that most of this is due to one item that weighs much more in Austria than elsewhere: restaurants and cafés.

  • Is Services Inflation a Catch-Up Story Everywhere in the Euro Area?

    Hochmuth and Petz (2026) explain why services inflation in the euro area has come down so slowly: before the pandemic, services became steadily more expensive relative to goods, the surge of goods prices in 2021 and 2022 pushed this relative price far below its trend, and part of today’s services inflation is services prices catching up. In the reproduction of the paper the euro area results hold up, but in Austria the story does not fit: the relative price of services is already above its trend. This post estimates the model for all 21 countries of the euro area to find out where the explanation holds and where it does not. The short answer: the mechanism is there almost everywhere, but it explains little of why services inflation has differed so much between countries since 2023.

  • Reproduction: Hochmuth, P., & Petz, N. (2026). On the persistence of services inflation and the price of services relative to goods.

    This post reproduces results from Hochmuth and Petz (2026) with bvartools, including the brief’s three descriptive charts: the composition of euro area inflation, and the relative price of services in the euro area and the United States.

  • Reproduction: Coelli, T. J. (1996). A guide to FRONTIER Version 4.1.

    For most of the 1990s and 2000s, estimating a stochastic frontier meant running FRONTIER 4.1, Tim Coelli’s Fortran program, and its guide (Coelli, 1996) was where one learnt how. The guide works through a small example: a Cobb-Douglas production frontier for 60 firms with half-normal inefficiency, estimated by maximum likelihood. Its data are distributed with the program and, today, with the R package frontier by Coelli and Henningsen, which implements FRONTIER 4.1 in R.

    This post reproduces that example twice: by maximum likelihood with frontier, which returns the guide’s printed estimates, and by Bayesian inference with bsfa. The second is the more interesting exercise, because the two approaches answer slightly different questions, and a sample of 60 is small enough for the difference to show.

  • Reproduction: Griffin, J. E., & Steel, M. F. J. (2007). Bayesian stochastic frontier analysis using WinBUGS.

    Griffin and Steel (2007) is a tutorial as much as a research paper. It shows how the Bayesian stochastic frontier models that van den Broeck, Koop, Osiewalski and Steel (1994) set out can be written down and estimated in WinBUGS, and its first example is the classic of the field: the costs of 123 US electric utilities in 1970, first analysed by Christensen and Greene (1976) and used by Greene (1990) and many others since. The paper prints its WinBUGS code, its priors and the posterior summaries it obtained, which makes it an unusually complete target for a reproduction.

    This post reproduces the exponential and half-normal cost frontiers of that example with the bsfa package, which samples the same models by data augmentation and elicits its priors in the way the paper does.

  • Reproduction: Koop, G., León-González, R., & Strachan, R. W. (2011). Bayesian inference in a time varying cointegration model.

    The Fisher hypothesis says that nominal interest rates move one for one with expected inflation, so that the real interest rate is stationary. In a vector error correction model (VECM) of a short-term interest rate \(r_t\) and inflation \(\pi_t\) it implies a single cointegrating relationship with the vector \((1, -1)'\). Tests of it on long samples give mixed results, and one reason may be that the relationship is not the same throughout: a hypothesis that holds in some decades and fails in others is rejected by a model that insists on one answer for all of them.

    Koop, León-González and Strachan (2011) develop a VECM whose cointegration space is allowed to change over time, and use it on exactly this question. The difficulty they solve is not computational but conceptual. The natural extension of a time varying parameter VAR – letting the cointegrating vectors follow a random walk – does not work, because only the space spanned by the vectors is identified, and a random walk on a normalised vector says nothing sensible about how that space moves. Their state equation instead implies that the space in one period is centred on the space of the period before, and that its marginal prior is uniform in every period.

    This post reproduces the two results of the application with bvartools: the path of the cointegrating coefficient in the paper’s preferred model (Fig. 1) and the log predictive likelihoods of the model variants (Tables 1 and 2).

  • Can a Bayesian VAR Beat Professional Forecasters?

    A comparison between the models one happens to have written down answers a narrow question: which of them fits and forecasts best. It does not answer whether any of them is worth using. The benchmark for that is the forecast somebody actually published and was held to. This post runs that comparison for Austria, where three Bayesian VAR models compete against the projections of the European Commission, the ECB, the IHS, the IMF, the Austrian central bank and WIFO – and against the simplest competitor of them all, which is to carry the last observation forward.

  • Setting up sparklyr

    The sparklyr package allows you to work with data sets, which are too large for the memory of your computer, by using the well-known verbs of dplyr on Apache Spark. However, before you can write a single line of such code, your machine has to be prepared for it. This is a bit more involved than the installation of an ordinary R package, because Spark is not written in R. It runs on the Java virtual machine and, therefore, needs a working Java installation as well as a copy of Spark itself. This post goes through those steps one by one.

  • Introduction to data.table

    The cleaning and transformation of data belong to the most time consuming parts of any economic analysis. Many graphical or statistical functions in R require specifically formatted data to work properly. Although the standard functions of R can be used to prepare your data for further analysis, some people find them a bit laborious for daily applications. Therefore, alternatives have been developed, which make data transformation in R easier and also faster. One of these alternatives is the data.table package. It is known for its very concise syntax and for its excellent performance on large data sets, which is why it is a popular choice whenever speed and memory consumption matter. In the following I give an introduction to the main elements of the data.table syntax. It covers the same operations as my introduction to dplyr, so that both approaches can be compared directly.

  • Introduction to sparklyr

    The cleaning and transformation of data belong to the most time consuming parts of any economic analysis. As long as a data set fits into the memory of your computer, packages like dplyr or data.table are all you need to get this job done. But once it does not, R alone reaches its limits, because it holds all its objects in memory. This is where Apache Spark comes into play. Spark is a computing engine, which distributes both the data and the calculations over the machines of a cluster – or over the cores of a single computer. The sparklyr package is the interface between R and Spark. Its most attractive feature for R users is that it translates the well-known verbs of dplyr into Spark SQL. This means that you can keep writing the code you already know and let it run on data which would never fit into your RAM. In the following I use the same example as in my introductions to dplyr and data.table, so that the three approaches can be compared directly.

  • Reproduction: Koop, G., & Korobilis, D. (2014). A new index of financial conditions.

    A financial conditions index (FCI) compresses a large number of financial market series – spreads, prices, volatilities, survey measures – into a single series that is meant to say whether financial conditions are tight or loose. The obvious tool for that job is a factor model. The harder question is which series should count towards the index, and by how much, given that the answer plainly changes over time: the TED spread said something quite different about the state of the financial system in 2008 than it did in 1995.

    Koop and Korobilis (2014) answer it by letting the factor loadings drift. Their index comes out of a factor augmented VAR (FAVAR) in which both the loadings and the transition coefficients follow random walks, so a series can enter and leave the index as the sample proceeds. What makes the paper more than a large state space model is how it is estimated: the priors on the innovation variances are replaced by forgetting factors, which reduces the whole estimation to two passes of a Kalman filter and smoother. No posterior simulation is involved, and the entire index over 175 quarters and 18 financial series is obtained in a hundredth of a second.

    This post reproduces the two exercises the paper is built around – the index itself and its real-time counterpart – using the fincond package.

  • Bayesian Inference of Structural Vector Autoregressions (SVAR) with the `bvartools` package

    The bvartools allows to perform Bayesian inference of Vector autoregressive (VAR) models, including structural VARs. This post guides through the Bayesian inference of SVAR models in R using the bvartools package.

    Data

    For this illustration we generate an artificial data set with three endogenous variables, which follows the data generating process

    \[y_t = A_1 y_{t - 1} + B \epsilon_t,\]

    where

    \[ A_1 = \begin{bmatrix} 0.3 & 0.12 & 0.69 \\ 0 & 0.3 & 0.48 \\ 0.24 & 0.24 & 0.3 \end{bmatrix} \text{, } B = \begin{bmatrix} 1 & 0 & 0 \\ -0.14 & 1 & 0 \\ -0.06 & 0.39 & 1 \end{bmatrix} \text{ and } \epsilon_t \sim N(0, I_3). \]

  • An Introduction to Dynamic Factor Models

    Introduction

    For some macroeconomic applications it might be interesting to see whether a set of observable variables depends on common drivers. The estimation of such common factors can be done using so-called factor analytical models, which have the form

    \[x_t = \lambda f_t + u_t,\]

    where \(x_t\) is an \(M\)-dimensional vector of observable variables, \(f_t\) is an \(N \times 1\) vector of unobserved factors, \(\lambda\) is an \(M \times N\) matrix of factor loadings and \(u_t\) is an error term.

  • Short Notes on Bayesian Inference of Vector Autoregressive Models

    During the past years I realised that econometric analysis can be understood as a craft. You learn your basics at school from more or less motivated/talented professors and then you are sent out into wild, where you are confronted with real life challenges that differ from the stylised exmples you have become used to during your studies. This comes with a bunch new insights that I want to document on this page. It should become a collection of notes on Bayesian VAR modelling that have become important to me over the last years.

  • An Introduction to Structural Vector Autoregression (SVAR)

    Vector autoregressive (VAR) models constitute a rather general approach to modelling multivariate time series. A critical drawback of those models in their standard form is their missing ability to describe contemporaneous relationships between the analysed variables. This becomes a central issue in the impulse response analysis for such models, where it is important to know the contemporaneous effects of a shock to the economy. Usually, researchers address this by using orthogonal impulse responses, where the correlation between the errors is obtained from the (lower) Cholesky decomposition of the error covariance matrix. This requires them to arrange the variables of the model in a suitable order. An alternative to this approach is to use so-called structural vector autoregressive (SVAR) models, where the relationship between contemporaneous variables is modelled more directly. This post provides an introduction to the concept of SVAR models and how they can be estimated in R.

  • An Introduction to Stationarity and Unit Roots in Time Series Analysis

    Concepts

    Basically stationarity means that a time series has a constant mean and constant variance over time. Although not particularly important for the estimation of parameters of econometric models these features are essential for the calculation of reliable test statistics and, hence, can have a significant impact on model selection.

    To illustrate this concept, let’s look at quarterly data on disposable income in billion DM from 1960 to 1982, which is data set E1 from Luetkepohl (2007).

  • An Introduction to Impulse Response Analysis of VAR Models

    Impulse response analysis is an important step in econometric analyes, which employ vector autoregressive models. Their main purpose is to describe the evolution of a model’s variables in reaction to a shock in one or more variables. This feature allows to trace the transmission of a single shock within an otherwise noisy system of equations and, thus, makes them very useful tools in the assessment of economic policies. This post provides an introduction to the concept and interpretation of impulse response functions as they are commonly used in the VAR literature and provides code for their calculation in R.

  • Introduction to dplyr

    The cleaning and transformation of data belong to the most time consuming parts of any economic analysis. Many graphical or statistical functions in R require specifically formatted data to work properly. Although the standard functions of R can be used to prepare your data for further analysis, some people find them a bit laborious for daily applications. Therefore, alternatives have been developed, which make data transformation in R easier and also faster. One of these alternatives is the dplyr package of the tidyverse. It has gained great popularity among R users and being familiar with its syntax can be considered a standard skill in R. In the following I give an introduction to some main functions of dplyr, which I also use extensively at work.

  • Preparing Your Workplace for an Analysis

    Create a working directory

    Usually, people want to keep the folder structure on their computers tidy, so that they and their co-workers understand, which documents and data were used for a particular project – even if that project was finished months ago. This should also be the case when you work with R. Therefore, I recommend to create a new folder for every new project, which becomes the so-called working directory. There you put all the files, which are necessary for a project. For example, for this introduction I created the folder r_intro in my file explorer and I recommend to do the same on your computer now.

  • An Introduction to Vector Error Correction Models (VECMs)

    One of the prerequisits for the estimation of a vector autoregressive (VAR) model is that the analysed time series are stationary. However, economic theory suggests that there exist equilibrium relations between economic variables in their levels, which can render these variables stationary without taking differences. This is called cointegration. Since knowing the size of such relationships can improve the results of an analysis, it would be desireable to have an econometric model, which is able to capture them. So-called vector error correction models (VECMs) belong to this class of models. The following text presents the basic concept of VECMs and guides through the estimation of such a model in R.

  • An Introduction to Bayesian VAR (BVAR) Models

    Bayesian methods have significantly gained in popularity during the last decades as computers have become more powerful and new software has been developed. Their flexibility and other advantageous features have made these methods also more popular in econometrics. This post gives a brief introduction to Bayesian VAR (BVAR) models and provides the code to set up and estimate a basic model with the bvartools package.

  • Bayesian Error Correction Models with Priors on the Cointegration Space

    Introduction

    This post provides the code to set up and estimate a basic Bayesian vector error correction (BVEC) model with the bvartools package. The presented Gibbs sampler is based on the approach of Koop et al. (2010), who propose a prior on the cointegration space.

    Data

    To illustrate the estimation process, the dataset E6 from Lütkepohl (2007) is used, which contains data on German long-term interest rates and inflation from 1972Q2 to 1998Q4.

  • Stochastic Search Variable Selection

    Introduction

    A general drawback of vector autoregressive (VAR) models is that the number of estimated coefficients increases disproportionately with the number of lags. Therefore, fewer information per parameter is available for the estimation as the number of lags increases. In the Bayesian VAR literature one approach to mitigate this so-called curse of dimensionality is stochastic search variable selection (SSVS) as proposed by George et al. (2008). The basic idea of SSVS is to assign commonly used prior variances to parameters, which should be included in a model, and prior variances close to zero to irrelevant parameters. By that, relevant parameters are estimated in the usual way and posterior draws of irrelevant variables are close to zero so that they have no significant effect on forecasts and impulse responses. This is achieved by adding a hierarchial prior to the model, where the relevance of a variable is assessed in each step of the sampling algorithm.

  • Reproduction: Timmer, M. P., Dietzenbacher, E., Los, B., Stehrer, R., & De Vries, G. J. (2015). An illustrated user guide to the world input–output database: the case of global automotive production.

    As international trade has become increasingly fragmented over the past decades the analysis of global value chains (GVC) has gained popularity in economic research. This post reproduces Timmer et al. (2015), who introduce the world input-output database (WIOD) and present basic concepts of GVC analysis.

    Data

    Timmer et al. (2015) use the 2013 vintage of the world input-output database (WIOD). The following code downloads the data from the project’s website, unzips it and loads the resulting STATA file into R using the readstata13 package.

  • William Shakespeare's Work in a Word Cloud

    Word or tag clouds seem to be quite popular at the moment. Although their analytical power might be limited, they do serve an aesthetic purpose and, for example, could be put on the cover page of a thesis or a presentation using the content of your work or the literature you went through. This post uses text data from the Gutenberg project to give a step-by-step introduction on how to create a wordcould in R.

  • An Introduction to Vector Autoregression (VAR)

    Since the seminal paper of Sims (1980) vector autoregressive models have become a key instrument in macroeconomic research. This post presents the basic concept of VAR analysis and guides through the estimation procedure of a simple model. When I started my undergraduate program in economics I occasionally encountered the abbreviation VAR in some macro papers. I was fascinated by those waves in the boxes titled impulse responses and wondered how difficult it would be to do such reseach on my own. I was motivated, but my first attempts were admittedly embarrassing. It took me quite a long time to figure out which kind of data can be analysed, how to estimate a VAR model and how to obtain meaningful impulse responses. Today, I think that there is nothing fancy about VAR models at all once you keep in mind some points.

  • Data Visualisation in R Using ggplot2

    A major challenge in data analysis is to summarize and present data with informative graphs. The ggplot2 package was specifically designed to help with this task. Since it is a very powerful and well documented package, this introduction will only focus on its basic syntax, so that the user gets a better understanding of how to read the supporting material on the internet.

    ggplot graphs are built with some kind of blocks, which usually start with the function ggplot. Its first argument contains the data object and the second argument is a further function called aes. It controls, which columns of the data frame are used for the axes, colours, shapes of the data points and further features of the graph. The remaining blocks are separated by plus + signs and – if not specified otherwise – take the information from the first block and add a certain aspect to the graph, for example additional lines or data points. To understand what this all means, let us look at some basic examples.

  • Installing R and RStudio

    For this introduction I recommend to install two software packages on your system:

    • R: The software, which does all the calculations.
    • RStudio: The working environment, where all the code will be developed.

    Note that the instructions of this section were written for a standard installation on a private computer. If you work on a corporate machine, the installation could be different due to different IT requirements of your company.

    Installing R

    A proper installation of R is the prerequisite of everything that will follow. Fortunately, installing R is easy and can be done quickly by following these steps:

  • Reproduction: Sheperd, B. (2016). The gravity model of international trade: A user guide.

    The updated paper and dataset can be downloaded from UNESCAP.

    Load libraries and read data

    library("AER")
    library("dplyr")
    library("foreign")
    library("ggplot2")
    library("lmtest")
    library("multiwayvcov")
    library("sampleSelection")
    
    services <- read.dta("servicesdataset_2016.dta")

    Correlations

    Table 1

    services <- services %>%
      mutate(ln_trade = log(trade),
             ln_distance = log(dist),
             ln_gdp_exp = log(gdp_exp),
             ln_gdp_imp = log(gdp_imp))
    
    cor_data <- services %>%
      filter(sector == "SER") %>%
      select(ln_trade, ln_gdp_exp, ln_gdp_imp, ln_distance) %>%
      na.omit() %>%
      filter(ln_trade > -Inf)
    
    round(cor(cor_data), 4)
    ##             ln_trade ln_gdp_exp ln_gdp_imp ln_distance
    ## ln_trade      1.0000     0.3643     0.3731     -0.2648
    ## ln_gdp_exp    0.3643     1.0000    -0.3103      0.0518
    ## ln_gdp_imp    0.3731    -0.3103     1.0000      0.0431
    ## ln_distance  -0.2648     0.0518     0.0431      1.0000

    Graphics

    Prepare data