Home Life Studies Research Resources Contact

An Introduction to R for Econometrics

This webpage has accompanied an introduction to R, delivered in the TA sessions for the 'Econometrics I' course of Jesús Crespo-Cuaresma at IHS Vienna in 2007.
It remains posted as a reference but is not as up-to-date as its collection of web references.


Installing R and the SciViews-R editor (under Windows)

  1. Installing R

  2. Install a GUI:

    The default graphical user interface (GUI) delivered with R does not offer much in terms of functionality. I have used several independent R-GUIs over the past and now finally settled with Rstudio. In general I have tested the following GUIs, all of which are open-source:
    • RStudio is a handy and stable inteface for any opeerating system. The interface is reminiscent of Matlab's GUI, and offers not only coding amenities, but also a nice integration of plots, help and a view on variables in the workspace.
    • The 'stable' version of Tinn-R from SciViews is a stable and lean GUI for R on Windows that I have used heavily in the past and still use. It's focus is on the script editor, with all the amenities known from other coding environments.
    • JGR, which is a quite handy GUI independent of the operating system. In the past there it had some issues with stability, but it is a very nice coding environment.
    • RKward is an interface for Linux-KDE that is nice to work with and stable as well.

Some useful references for starting with R

Tutorials on R

'Lecture' material:

Information on lecture rooms

Most tutorials will be held in 6., Stumpergasse 56, mainly in the 'EDV Raum' at ground floor.
Only one lecture room (namely 'Schottenfeldgasse') is at 7., Schottenfeldgasse 29 in the third floor (ring if the office door is not open).

Homeworks in R


Homeworks in R have to be submitted as an R file via e-mail. This R file should work by direct execution, i.e. I should be able to type source("yourfile.R") and get the result printed on the console or into an output file. For the first homework, you may as well submit the necessary data file such that the routine works. For the subsequent homework, your R file should directly handle the data set given to you.

Homeworks will be graded along four dimensions:

Homework sample solutions:

  1. Homework sheet 1, no R exercises.
  2. Homework sheet 2, exercise 2: The data file in tab-separated format and a sample .R script exemplify the solution to the exercise.
    To examine it, download the .R file and the data file, and type in R setwd("path to which you downloaded the files") and then source("es2ex2.R").
  3. Homework sheet 3, exercise 3: The data file in CSV format, simply stored out of the original Excel file.
    This data contains many non-availables (NAs), and there are, in principle, two methods to adress this problem:
    • Cleaning the sample regressions from NAs individually:
      This approach was chosen by all of the students. A commented sample solution outlining this approach can be found in SalaIMartin_es3_3.R.
      To examine it, download it and the the data file and execute it via the source() command as above. Execution takes about 50 seconds on a Pentium M.
    • Cleaning the data first, and then do the individual regressions:
      This is the 'more right' approach, in my opinion. Moreover it lends itself to the use of the Frisch-Waugh theorem for the fixed regressors - which in turn enables the entire simulation to run in a few seconds. However, there are only 32 countries which are clean of NAs. So the data basis is quite weak.
      Sample code for this approach is in the file SalaIMartinFrischWaugh_es3_3.R. It is quite similar to the solution above.