This post was written jointly with Yulia Marchenko, Executive Director of Statistics, StataCorp.
Table of Contents
Overview
1PL model
2PL model
3PL model
4PL model
5PL model
Conclusion
Overview
Item response theory (IRT) is used for modeling the relationship between the latent abilities of a group of subjects and the examination items used for measuring their abilities. Stata 14 introduced a suite of commands for fitting IRT models using maximum likelihood; see, for example, the blog post Spotlight on irt by Rafal Raciborski and the [IRT] Item Response Theory manual for more details. In this post, we demonstrate how to fit Bayesian binary IRT models by using the redefine() option introduced for the bayesmh command in Stata 14.1. We also use the likelihood option dbernoulli() available as of the update on 03 Mar 2016 for fitting Bernoulli distribution. If you are not familiar with the concepts and jargon of Bayesian statistics, you may want to watch the introductory videos on the Stata Youtube channel before proceeding.
Introduction to Bayesian analysis, part 1 : The basic concepts
Introduction to Bayesian analysis, part 2: MCMC and the MetropolisHastings algorithm
We use the abridged version of the mathematics and science data from DeBoeck and Wilson (2004), masc1. The dataset includes 800 student responses to 9 test questions intended to measure mathematical ability.
The irt suite fits IRT models using data in the wide form – one observation per subject with items recorded in separate variables. To fit IRT models using bayesmh, we need data in the long form, where items are recorded as multiple observations per subject. We thus reshape the dataset in a long form: we have a single binary response variable, y, and two index variables, item and id, which identify the items and subjects, respectively. This allows us to Read more…
I have posted a series of entries about programming an estimation command in Stata. They are best read in order. The comprehensive list below allows you to read them from first to last, at your own pace.

Programming estimators in Stata: Why you should
To help you write Stata commands that people want to use, I illustrate how Stata syntax is predictable and give an overview of the estimationpostestimation structure that you will want to emulate in your programs.

Programming an estimation command in Stata: Where to store your stuff
I discuss the difference between scripts and commands, and I introduce some essential programming concepts and constructions that I use to write the scripts and commands.

Programming an estimation command in Stata: Global macros versus local macros
I discuss a pair of examples that illustrate the differences between global macros and local macros.

Programming an estimation command in Stata: A first adocommand
I discuss the code for a simple estimation command to focus on the details of how to implement an estimation command. The command that I discuss estimates the mean by the sample average. I begin by reviewing the formulas and a dofile that implements them. I subsequently introduce Read more…
In a previous post I illustrated that the probit model and the logit model produce statistically equivalent estimates of marginal effects. In this post, I compare the marginal effect estimates from a linear probability model (linear regression) with marginal effect estimates from probit and logit models.
My simulations show that when the true model is a probit or a logit, using a linear probability model can produce inconsistent estimates of the marginal effects of interest to researchers. The conclusions hinge on the probit or logit model being the true model.
Simulation results
For all simulations below, I use a sample size of 10,000 and 5,000 replications. The true datagenerating processes (DGPs) are constructed using Read more…
I discuss a command that computes ordinary leastsquares (OLS) results in Mata, paying special attention to the structure of Stata programs that use Mata work functions.
This command builds on several previous posts; at a minimum, you should be familiar with Programming an estimation command in Stata: A first adocommand using Mata and Programming an estimation command in Stata: Computing OLS objects in Mata.
This is the fifteenth post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.
An OLS command with Mata computations
The Stata command myregress11 computes the results in Mata. The syntax of the myregress11 command is
myregress11 depvar [indepvars] [if] [in] [, noconstant]
where indepvars can contain factor variables or timeseries variables.
In the remainder of this post, I discuss the code for myregress11.ado. I recommend that you click on the file name to download the code. To avoid scrolling, view the code in the dofile editor, or your favorite text editor, to see the line numbers.
I do not discuss Read more…
We often use probit and logit models to analyze binary outcomes. A case can be made that the logit model is easier to interpret than the probit model, but Stata’s margins command makes any estimator easy to interpret. Ultimately, estimates from both models produce similar results, and using one or the other is a matter of habit or preference.
I show that the estimates from a probit and logit model are similar for the computation of a set of effects that are of interest to researchers. I focus on the effects of changes in the covariates on the probability of a positive outcome for continuous and discrete covariates. I evaluate these effects on average and at the mean value of the covariates. In other words, I study the average marginal effects (AME), the average treatment effects (ATE), the marginal effects at the mean values of the covariates (MEM), and the treatment effects at the mean values of the covariates (TEM).
First, I present the results. Second, I discuss the code used for the simulations.
Results
In Table 1, I present the results of a simulation with 4,000 replications when the true data generating process (DGP) satisfies the assumptions of a probit model. I show the Read more…
\(\newcommand{\epsilonb}{\boldsymbol{\epsilon}}
\newcommand{\ebi}{\boldsymbol{\epsilon}_i}
\newcommand{\Sigmab}{\boldsymbol{\Sigma}}
\newcommand{\betab}{\boldsymbol{\beta}}
\newcommand{\eb}{{\bf e}}
\newcommand{\xb}{{\bf x}}
\newcommand{\xbit}{{\bf x}_{it}}
\newcommand{\xbi}{{\bf x}_{i}}
\newcommand{\zb}{{\bf z}}
\newcommand{\zbi}{{\bf z}_i}
\newcommand{\wb}{{\bf w}}
\newcommand{\yb}{{\bf y}}
\newcommand{\ub}{{\bf u}}
\newcommand{\Xb}{{\bf X}}
\newcommand{\Mb}{{\bf M}}
\newcommand{\Xtb}{\tilde{\bf X}}
\newcommand{\Wb}{{\bf W}}
\newcommand{\Vb}{{\bf V}}\)I present the formulas for computing the ordinary leastsquares (OLS) estimator and show how to compute them in Mata. This post is a Mata version of Programming an estimation command in Stata: Using Stata matrix commands and functions to compute OLS objects. I discuss the formulas and the computation of independencebased standard errors, robust standard errors, and clusterrobust standard errors.
This is the fourteenth post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.
OLS formulas
Recall that the OLS point estimates are given by
\[
\widehat{\betab} =
\left( \sum_{i=1}^N \xb_i’\xb_i \right)^{1}
\left(
\sum_{i=1}^N \xb_i’y_i
\right)
\]
where \(\xb_i\) is the \(1\times k\) vector of independent variables, \(y_i\) is the dependent variable for each of the \(N\) sample observations, and the model for \(y_i\) is
\[
y_i = \xb_i\betab’ + \epsilon_i
\]
If the \(\epsilon_i\) are independently and identically distributed (IID), we estimate Read more…
I discuss a sequence of adocommands that use Mata to estimate the mean of a variable. The commands illustrate a general structure for Stata/Mata programs. This post builds on Programming an estimation command in Stata: Mata 101, Programming an estimation command in Stata: Mata functions, and Programming an estimation command in Stata: A first adocommand.
This is the thirteenth post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.
Using Mata in adoprograms
I begin by reviewing the structure in mymean5.ado, which I discussed Read more…
I show how to write a function in Mata, the matrix programming language that is part of Stata. This post uses concepts introduced in Programming an estimation command in Stata: Mata 101.
This is the twelfth post in the series Programming an estimation command in Stata. I recommend that you start at the beginning. See Programming an estimation command in Stata: A map to posted entries for a map to all the posts in this series.
Mata functions
Commands do work in Stata. Functions do work in Mata. Commands operate on Stata objects, like variables, and users specify options to alter the behavior. Mata functions accept arguments, operate on the arguments, and may return a result or alter the value of an argument to contain a result.
Consider myadd() defined below.
Code block 1: myadd()
mata:
function myadd(X, Y)
{
A = X + Y
return(A)
}
end
myadd() accepts two arguments, X and Y, puts the sum of X and Y into A, and returns A. For example, Read more…
Converting a string date
Stata has a wide array of tools to work with dates. You can have dates in years, months, or even milliseconds. In this post, I will provide a brief tour of working with dates that will help you get started using all of Stata’s tools.
When you load a dataset, you will notice that every variable has a display format. For date variables, the display format is %td for daily dates, %tm for monthly dates, etc. Let’s load the wpi1 dataset as Read more…
Reflecting on the year, Stata has a lot to be thankful for—we released Stata 14, celebrated 30 years of Stata, and had the pleasure of meeting and working with many great people, including our Stata Press authors.
Are you interested in writing a book about Stata or just a book on statistics? We’d love to work with you too. Stata Press offers books with clear, stepbystep examples that make learning and teaching easier. Read more about our submission guidelines, or contact us to get started.
If you’re searching for a good book to read during the holidays, check out our full list of books or our most recent ones below. If you’d like to be notified when new books are released, sign up for Stata Press email alerts.
I hope you all have a great New Year!
Stata for the Behavioral Sciences
Michael N. Mitchell’s Stata for the Behavioral Sciences is an ideal reference for Read more…