Analysis of Stable Matchings

Implements structural estimators to correct for the sample selection bias from observed outcomes in matching markets. This includes one-sided matching of agents into groups as well as two-sided matching of students to schools. The package also contains algorithms to find stable matchings in the three most common matching problems: the stable roommates problem, the college admissions problem, and the house allocation problem.


Package documentation is available at and the vignette is available from the CRAN page. An application of the estimator in function stabit is in Klein (2015).


Get started by installing the R software for statistical computing.

To get the latest stable version of the package from CRAN:


Under Linux, the dependency package gmp requires that you have GNU MP (> 4.1.4) installed: $ sudo apt-get install libgmp-dev. See

To get the most recent development version from GitHub:


or from R-Forge:

install.packages("matchingMarkets", repos="")

Java Note 1: If you get a Java error such as JAVA_HOME cannot be determined from the Registry, this can be resolved by either running install.packages() with the INSTALL_opts = "--no-multiarch" argument or by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using. See this post and download the Java version from the Oracle website.

Java Note 2: If the installation of the dependent rJava package fails with configuration failed for package ‘rJava’, this can be fixed in Linux by $ sudo apt-get install r-cran-rjava.


The matchingMarkets R package comes with two estimators:

  • stabit: Implements a Bayes estimator that corrects for sample selection in matching markets when the selection process is a one-sided matching game (i.e. group formation).

  • stabit2: Implements the Bayes estimator for a two-sided matching game (i.e. the college admissions and stable marriage problems).

and algorithms that can be used to simulate matching data:

  • hri: Constraint model for the hospital/residents problem. Finds all stable matchings in two-sided matching markets. Implemented for both the stable marriage problem (one-to-one matching) and the hospital/residents problem, also known as college admissions problem (many-to-one matching).

  • hri2: Roth-Peranson Algorithm for the hospital/residents problem with couples. Finds the resident-optimal stable matching (if one exists) in the two-sided matching market.

  • iaa: Immediate Acceptance Algorithm (a.k.a. Boston mechanism): First-preference-first algorithm used for school choice in many countries. And Gale-Shapley Deferred Acceptance Algorithm.

  • sri: Constraint model for the stable roommates problem. Finds all stable matchings in the roommates problem (one-sided matching market).

  • plp: Partitioning Linear Programme. Finds the unique matching in the roommates problem (one-sided matching market) with transferable utility.

  • rsd: Random serial dictatorship mechanism.

  • ttc: Top-Trading-Cycles Algorithm. Finds efficient matchings in the housing market problem.

  • ttc2: Top-Trading-Cycles Algorithm for a two sided matching problem.

  • ttcc: Top-Trading-Cycles and Chains Algorithm for the kidney exchange problem.

Functions hri and sri are based on Patrick Prosser's n-ary constraint encoding model. They allow for incomplete preference lists (some agents find certain agents unacceptable) and unbalanced instances (unequal number of agents on both sides).


matchingMarkets 1.0-1

Please note that only the most significant changes are reported here. A full ChangeLog is available in the log messages of the SVN repository on R-Forge and on GitHub.

This is a minor update

  • Added data generating function for exploded logit in

matchingMarkets 1.0-0

This is a major update

  • Finalised estimators in stabit2 function, as well as algorithms in hri and hri2 for two-sided matching markets.

matchingMarkets 0.3-6

This is a minor update

  • Added top-trading-cycle functions ttc2 and ttcc; random serial dictatorship rsd; and a function to check the stability of a given matching stabchk.

matchingMarkets 0.3-5

This is a minor update

  • Added R wrapper for Roth-Peranson Algorithm in function hri2.

matchingMarkets 0.3-3

This is a minor update

  • Implemented multi-core parrallel processing for estimators in function stabit2, which can be specified using the nCores argument.
  • Updated immediate acceptance algorithm iaa and top-trading-cycles ttc functions. Thanks to Sándor Sóvágó at Tinbergen Institute and Kevin Breuer at University of Cologne for the reports.

matchingMarkets 0.3-1

This is a major update

  • Replaced stable matching algorithms with constraint programming model implemented for hospital/residents problem hri and stable roommates sri with incomplete lists.
  • Added plot and summary methods for estimators.
  • Allowed for thinning in stabit2 function.

matchingMarkets 0.2-2

This is a minor update

  • Allowed for two selection equations in stabit2 function for two-sided matching markets.

matchingMarkets 0.2-1

This is a major update

  • Added stabit2 function for two-sided matching markets.

matchingMarkets 0.1-6

This is a major update

matchingMarkets 0.1-5

This is a minor update.

  • Fixed daa function for college admissions problems when number of students exceeds number of colleges. Thanks to Jan Tilly at University of Pennsylvania for the report.

matchingMarkets 0.1-1

Initial commit.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.0-2 by Thilo Klein, 6 months ago,

Report a bug at

Browse source code at

Authors: Thilo Klein [aut, cre] , Robert Aue [ctb] , Sven Giegerich [ctb] , Alexander Sauer [ctb]

Documentation:   PDF Manual  

Task views: Bayesian Inference, Econometrics, Empirical Finance, Optimization and Mathematical Programming

GPL (>= 2) license

Imports Rcpp, RcppProgress, rJava, lpSolve, lattice, partitions, parallel, stats, utils

Suggests knitr, ggplot2, grDevices, graphics

Linking to Rcpp, RcppProgress, RcppArmadillo

System requirements: Java, C++11

Imported by PAutilities.

See at CRAN