Red Door Analytics
2020 framework introduced
Crowther, Stata Journal
SSC install ssc install merlin
3 wrapper commands
stmerlin · stmixed · morgana
4+ model classes only in Stata
joint · multistate · CR

merlin for Stata is the original implementation of the merlin framework, introduced in Crowther (2020). It remains the right choice for many applied and methodological projects — including the multivariate joint models, multistate survival models, and competing-risks structures that have not yet returned to the R implementation.

merlin v3 for Stata is in build, with a rebuilt likelihood engine — analytic gradients and Hessians that run 2–4× faster than v2.4.7 on random-effects, time-dependent, and numerically-integrated fits — alongside the broadest model class of any merlin implementation. The R implementation is a parallel ground-up rewrite; its coverage will expand over time, with the Stata-only classes arriving in R after v2.

Stata merlin is actively developed — v3 is the next milestone — and remains central to active teaching, published methods work, and HTA submissions.

What v3 will need, and what it takes away

v3 requires Stata 19.5. Four things that work in v2.5.0 will not: exptorcs, the Firth correction in family(cox, firth), exposure() on a model equation — use offset(), which is what it should always have been — and ltruncated(, marginal) on a model with random effects, which is refused rather than silently given the wrong denominator. Model evaluation leaves merlin altogether: concordance, calibration, Brier scores, decision curves and cross-validation become gawain, so they can be used on a model fitted in anything. Ask us if a do-file of yours depends on one of these.

Installation

Install merlin and its wrappers

The core merlin package ships from SSC. The stmerlin and stmixed wrappers, and the morgana Bayesian companion, ship from Red Door Analytics' GitHub.

Stata · install commands
* Core package
ssc install merlin

* Wrappers from Red Door Analytics' GitHub
net install stmerlin, from("https://raw.githubusercontent.com/RedDoorAnalytics/stmerlin/main/")
net install stmixed,  from("https://raw.githubusercontent.com/RedDoorAnalytics/stmixed/main/")

* morgana — Bayesian survival (prefix to stmerlin)
net install morgana, from("https://raw.githubusercontent.com/RedDoorAnalytics/morgana/main/")

* Built-in help
help merlin
help stmerlin
help stmixed
help morgana
The merlin family of commands

Three wrappers on the same engine

Each wrapper is built on the merlin engine and accepts the full merlin specification language where needed.

stmerlin
Single-outcome survival

Streamlined wrapper for single-outcome survival models in st-set data. Reduces the merlin specification to the minimum needed for standard survival analysis, including Royston-Parmar, Weibull, Gompertz, exponential, and user-defined hazard forms, with full TDE support.

stmixed
Mixed-effects survival

Wrapper for multilevel and mixed-effects survival models. Convenient when fitting random-intercept and random-slope survival models at multiple hierarchical levels, with the same flexible baseline hazard options as stmerlin.

morgana
Bayesian survival

Bayesian flexible parametric survival as a prefix to stmerlin: morgana hands the model to Stata's bayesmh, passing priors straight through, so any stmerlin model gains full posterior uncertainty. Available now — net install from GitHub (requires merlin and stmerlin).

Featured methodological specialty

Joint longitudinal-survival modelling

Joint modelling of one or more longitudinal biomarkers with one or more time-to-event outcomes is the specialty merlin for Stata is best known for — and the model class with the deepest methodological roots in the team's published work, over a decade and counting.

The Stata original · since 2012

The reference implementation for multivariate joint modelling in Stata

merlin for Stata fits multiple longitudinal outcomes (continuous, count, time-to-event) sharing a random-effects structure, multiple time-to-event outcomes linked via shared frailty, and association structures including current value, current slope, cumulative, and user-defined forms. Joint models with delayed entry, interval censoring, and multilevel hierarchical structure are supported.

20+ MC publications Crowther 2012 framework paper Dedicated short course
See the joint modelling short course →

merlin for R reaches core parity on joint models in v2.2+. Stata merlin is the joint-modelling implementation — and, as the depth-of-feature one, likely remains so for some time after R lands the core capability.

Where Stata merlin also leads

Beyond joint modelling

Three further model classes ship in Stata merlin today, and remain on the roadmap for merlin for R (v2.1+).

01

Multistate survival models

Arbitrary transition structures with shared frailty. Used in chronic-disease cost-effectiveness modelling and progression analysis. Returns to R as part of v2.1+.

02

Competing risks

Within the unified specification, including cause-specific hazards and direct cumulative incidence modelling. Returns to R in v2.1.

03

Recurrent events

Gap-time and total-time parametrisations. Returns to R as part of the v2.1 release.

Performance

v3.0.0 against v2.4.7

v3.0.0 rebuilds the likelihood engine with analytic gradients and Hessians. The same models converge to the same answers as v2.4.7 — the log-likelihoods match on every scenario — and the random-effects, time-dependent and numerically-integrated fits are the ones that gain most. Simple fixed-effects fits are barely changed.

All ten scenarios, with seconds →

Choosing an implementation

When to use Stata merlin

If your team works in Stata, Stata merlin is the right starting point for any merlin project. The package is mature and actively developed — merlin v3 will bring a rebuilt, analytic-gradient engine 2–4× faster than v2.4.7 on random-effects, time-dependent, and numerically-integrated fits — the documentation is comprehensive, and the model class is the broadest currently available in the framework.

If you have a choice of language for a new project, the decision rule is straightforward: use merlin for R or Stata merlin by team preference where their coverage overlaps, and reach for Stata specifically when you need its broader model class — most commonly multivariate joint models, multistate models, competing risks, or recurrent events. Both implementations are actively developed and share the same underlying specification language and the same development team.

A choice not a fork

R and Stata are independent implementations on a shared framework. Estimates, predictions, and methodological choices align across the two; teams that work in both languages can move between implementations without learning two specifications. See merlin for R →

Work with the team

The people who build merlin, on your project

Beyond bug reports and feature requests, the team that built merlin and the multistate family takes the work on directly — applied survival, multistate, and joint-modelling analysis, bespoke methods development, and submission support. See how we work → or get in touch.

Methodology and citation

If you use Stata merlin in published work

Framework paper
Crowther, MJ (2020)
merlin — a unified modelling framework for data analysis and methods development in Stata. Stata Journal 20(4):763–784. Read →
Source repositories
github.com/RedDoorAnalytics
stmerlin, stmixed, and morgana. Bug reports and feature requests on the per-repo issue trackers.
Training and courses
RDA short courses
Survival analysis, joint modelling, multistate, multilevel survival — open enrolment and bespoke. See training →

Working with Stata merlin?

Bug reports, feature requests, training enquiries, and commercial-support discussions all start with the same conversation. The merlin team is on contract for the work that matters.

Get in touch Validated for regulated work