Using R for Qualitative Choice Models
R is a programming language that can be very useful for estimating sophisticated econometric models. In fact, many statistical procedures have been written for R. Although gretl is very powerful, there are still many things that it won’t do out of the box. The ability to export gretl data into R makes it possible to do some very fancy econometrics with relative ease. The proliferation of new procedures in R comes as some cost though. Although the packages that are published at CRAN (http://cran. r-project. org/) have met certain standards, there is no assurance that any of them do what they intend correctly. Gretl, though open source, is more controlled in its approach. There are two major programmers that vet what gretl does and an active community of users that experiment and test the outcomes. Gretl users can add functions, just as R users do, but the basic set of gretl routines have been tested against known results. Mistakes occur, but they are usually rooted out and fixed by Professor Cottrell or Lucchetti before most people notice.
To use any of the R packages, you’ll need a copy of R, internet access, and the ability to install these to a local drive. A package is just a collection of programs and documentation written in R that make it easier to use for specific tasks. In the appendix D we use a package to read in data saved in Stata’s format and below another to estimate qualitative choice models using a Bayesian approach.
The R software package that is used to estimate qualitative choice models is called MCMC – pack. MCMCpack stands for Markov Chain Monte Carlo package and it can be used to estimate every qualitative choice model in this chapter. We will just use it to estimate multinomial logit, conditional logit, and ordered probit. So, let’s take a quick look at MCMCpack and what it does.
The Markov chain Monte Carlo (MCMC) methods are basic numerical tools that are often used to compute Bayesian estimators. In Bayesian analysis one combines what one already knows (called the prior) with what is observed through the sample (the likelihood function) to estimate the parameters of a model. The information available from the sample information is contained in the likelihood function; this is the same likelihood function discussed in your book. If we tell the Bayesian estimator that everything we know is contained in the sample, then the two estimators are essentially the same. That is what happens with MCMCpack under its defaults.
The biggest difference is in how the two estimators are computed. The MLE is computed using numerical optimization of the likelihood function, whereas MCMCpack uses simulation to accomplish virtually the same thing. See Lancaster (2004) or Koop (2003) for an introduction to Bayesian methods and its relationship to maximum likelihood.
The MCMC creates a series of estimates-called a (Markov) chain-and that series of estimates has an empirical probability distribution. Under the proper circumstances the probability distribution of the chain will mimic that of the MLE. Various features of the chain can be used as estimates. For instance, the sample mean is used by MCMCpack to estimate the parameters of the multinomial logit model. MCMCpack uses variation within the chain to compute the MLE variance covariance matrix, which is produced using the summary command.
One piece of information that you must give to MCMCpack is the desired length of your Markov chain. In the examples here, I chose 20,000, which is the number used in the sample programs included in MCMCpack. Longer chains tend to be more accurate, but take longer to compute. This number gets us pretty close to the MLEs produced by gretl and by Stata.