Programming an estimation command in Stata: A map to posted entries
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 adofile programming and discuss two versions of the command. Along the way, I illustrate some of the postestimation features that work after the command.

I present the formulas for computing the ordinary leastsquares (OLS) estimator, and I discuss some dofile implementations of them. I discuss the formulas and the computation of independencebased standard errors, robust standard errors, and cluster–robust standard errors. I introduce the Stata matrix commands and matrix functions that I use in adocommands that I discuss in upcoming posts.

Programming an estimation command in Stata: A first command for OLS
I show how to write a Stata estimation command that implements the OLS estimator by explaining the code.

Programming an estimation command in Stata: A better OLS command
I use the syntax command to improve the command that implements the OLS estimator that I discussed in Programming an estimation command in Stata: A first command for OLS. I show how to require that all variables be numeric variables and how to make the command accept timeseries operated variables.

Programming an estimation command in Stata: Allowing for sample restrictions and factor variables
I modify the OLS command discussed in Programming an estimation command in Stata: A better OLS command to allow for sample restrictions, to handle missing values, to allow for factor variables, and to deal with perfectly collinear variables.

Programming an estimation command in Stata: Allowing for options
I make three improvements to the command that implements the OLS estimator that I discussed in Programming an estimation command in Stata: Allowing for sample restrictions and factor variables. First, I allow the user to request a robust estimator of the variance–covariance of the estimator. Second, I allow the user to suppress the constant term. Third, I store the residual degrees of freedom in e(df_r) so that test will use the t or F distribution instead of the normal or chisquared distribution to compute the pvalue of Wald tests.

Programming an estimation command in Stata: Using a subroutine to parse a complex option
I make two improvements to the command that implements the OLS estimator that I discussed in Programming an estimation command in Stata: Allowing for options. First, I add an option for a cluster–robust estimator of the variance–covariance of the estimator (VCE). Second, I make the command accept the modern syntax for either a robust or a cluster–robust estimator of the VCE. In the process, I use subroutines in my adoprogram to facilitate the parsing, and I discuss some advanced parsing tricks.

Programming an estimation command in Stata: Mata 101
I introduce Mata, the matrix programming language that is part of Stata.

Programming an estimation command in Stata: Mata functions
I show how to write a function in Mata, the matrix programming language that is part of Stata.

Programming an estimation command in Stata: A first adocommand using Mata
I discuss a sequence of adocommands that use Mata to estimate the mean of a variable. The commands illustrate a general structure for StataMata programs.

Programming an estimation command in Stata: Computing OLS objects in Mata
I present the formulas for computing the 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 cluster–robust standard errors.

Programming an estimation command in Stata: An OLS command using Mata
I discuss a command that computes OLS results in Mata, paying special attention to the structure of Stata programs that use Mata work functions.

I show how to use the undocumented command _vce_parse to parse the options for robust or cluster–robust estimators of the VCE. I then discuss myregress12.ado, which performs its computations in Mata and computes an IIDbased, a robust, or a cluster–robust estimator of the VCE.

Programming an estimation command in Stata: A review of nonlinear optimization using Mata
I review the theory behind nonlinear optimization and get some practice in Mata programming by implementing an optimizer in Mata. This post is designed to help you develop your Mata programming skills and to improve your understanding of how the Mata optimization suites optimize() and moptimize() work.

Programming an estimation command in Stata: Using optimize() to estimate Poisson parameters
I show how to use optimize() in Mata to maximize a Poisson loglikelihood function and to obtain estimators of the VCE based on IID observations or on robust methods.

Programming an estimation command in Stata: A poisson command using Mata
I discuss mypoisson1, which computes Poissonregression results in Mata. The code in mypoisson1.ado is remarkably similar to the code in myregress11.ado, which computes OLS results in Mata, as I discussed in Programming an estimation command in Stata: An OLS command using Mata.

Programming an estimation command in Stata: Handling factor variables in optimize()
I discuss a method for handling factor variables when performing nonlinear optimization using optimize(). After illustrating the issue caused by factor variables, I present a method and apply it to an example using optimize().

mypoisson2.ado handles factor variables and computes its Poisson–regression results in Mata. I discuss the code for mypoisson2.ado, which I obtained by adding the method for handling factor variables discussed in Programming an estimation command in Stata: Handling factor variables in optimize() to mypoisson1.ado, discussed in Programming an estimation command in Stata: A poisson command using Mata.

mypoisson3.ado adds options for a robust or a cluster–robust estimator of the variance–covariance of the estimator (VCE) to mypoisson2.ado, which I discussed in Programming an estimation command in Stata: Handling factor variables in a poisson command using Mata. mypoisson3.ado parses the vce() option using the techniques I discussed in Programming an estimation command in Stata: Adding robust and cluster–robust VCEs to our Matabased OLS command. I show how to use optimize() to compute the robust or cluster–robust VCE.

Using analytically computed derivatives can greatly reduce the time required to solve a nonlinear estimation problem. I show how to use analytically computed derivatives with optimize(), and I discuss mypoisson4.ado, which uses these analytically computed derivatives. Only a few lines of mypoisson4.ado differ from the code for mypoisson3.ado, which I discussed in Programming an estimation command in Stata: Allowing for robust or cluster–robust standard errors in a poisson command using Mata.

Programming an estimation command in Stata: Making predict work
I make predict work after mypoisson5 by writing an adocommand that computes the predictions and by having mypoisson5 store the name of this new adocommand in e(predict).

Programming an estimation command in Stata: Certifying your command
Before you use or distribute your estimation command, you should verify that it produces correct results and write a dofile that certifies that it does so. I discuss the processes of verifying and certifying an estimation command, and I present some techniques for writing a dofile that certifies mypoisson5, which I discussed in previous posts.

Programming an estimation command in Stata: Nonlinear leastsquares estimators
I want to write adocommands to estimate the parameters of an exponential conditional mean (ECM) model and probit conditional mean (PCM) model by nonlinear least squares (NLS). Before I can write these commands, I need to show how to trick optimize() into performing the Gauss–Newton algorithm and apply this trick to these two problems.

Programming an estimation command in Stata: Consolidating your code
I write adocommands that estimate the parameters of an exponential conditional mean model and a probit conditional mean model by nonlinear least squares, using the methods that I discussed in the post Programming an estimation command in Stata: Nonlinear leastsquares estimators. These commands will either share lots of code or repeat lots of code, because they are so similar. It is almost always better to share code than to repeat code. Shared code only needs to be changed in one place to add a feature or to fix a problem; repeated code must be changed everywhere. I introduce Mata libraries to share Mata functions across adocommands, and I introduce wrapper commands to share adocode.

Programming an estimation command in Stata: Writing an estat postestimation command
estat commands display statistics after estimation. Many of these statistics are diagnostics or tests used to evaluate model specification. Some statistics are available after all estimation commands; others are command specific. I illustrate how estat commands work and then show how to write a commandspecific estat command for the mypoisson command that I have been developing.
Pingback: The Stata Blog » Testing model specification and using the program version of gmm()
Pingback: The Stata Blog » Programming an estimation command in Stata: Making predict work()
Pingback: The Stata Blog » Programming an estimation command in Stata: Certifying your command()
Pingback: The Stata Blog » Programming an estimation command in Stata: Adding analytical derivatives to a poisson command using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Allowing for robust or cluster–robust standard errors in a poisson command using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Handling factor variables in a poisson command using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Handling factor variables in optimize()()
Pingback: The Stata Blog » Programming an estimation command in Stata: A poisson command using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Using optimize() to estimate Poisson parameters()
Pingback: The Stata Blog » Programming an estimation command in Stata: A review of nonlinear optimization using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Adding robust and clusterrobust VCEs to our Matabased OLS command()
Pingback: The Stata Blog » Programming an estimation command in Stata: An OLS command using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Computing OLS objects in Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: A first adocommand using Mata()
Pingback: The Stata Blog » Programming an estimation command in Stata: Mata functions()
Pingback: The Stata Blog » Programming an estimation command in Stata: Mata 101()
Pingback: The Stata Blog » Programming an estimation command in Stata: Using a subroutine to parse a complex option()
Pingback: The Stata Blog » Programming an estimation command in Stata: Allowing for options()
Pingback: The Stata Blog » Programming an estimation command in Stata: Allowing for sample restrictions and factor variables()
Pingback: The Stata Blog » Programming an estimation command in Stata: A better OLS command()
Pingback: The Stata Blog » Programming an estimation command in Stata: A first command for OLS()
Pingback: The Stata Blog » Programming an estimation command in Stata: Using Stata matrix commands and functions to compute OLS objects()
Pingback: The Stata Blog » Programming an estimation command in Stata: A first adocommand()
Pingback: The Stata Blog » Programming an estimation command in Stata: Global macros versus local macros()
Pingback: The Stata Blog » Programming an estimation command in Stata: Where to store your stuff()
Pingback: The Stata Blog » Programming an estimation command in Stata: Nonlinear leastsquares estimators()
Pingback: The Stata Blog » Programming an estimation command in Stata: Writing an estat postestimation command()