*! version 1.0.0 31.01.2018

help mixmcm also see: mlogit, fmlogit

Title

mixmcm -- Estimation of finite mixture of Markov chain models by maximum likelihood (ML) and the Expectation-Maximization (EM) algorithm.

Syntax

mixmcm
depvar
[indepvars] [if] [in] [weight],
id(varname)
timevar(varname)
[noconstant
entry(varlist)
exitcode(name)
ncomponents(suboptions)
membership(varlist)
emiterate(suboptions)
constraints(clist)]

Main
* id(varname) numeric variable identifying agents

* timevar(varname) numeric variable identifying time

noconstant suppress constant term in the specification of transition probabilities

entry(varlist) specify dependent and explanatory variables for entry probabilities

exitcode(name) state indicating exits

ncomponents(ncomponents_suboptions) specify options for the number of components

membership(varlist) specify explanatory variables for component membership probabilities

emiterate(emiterate_suboptions) specifiy options for EM algorithm iterations

constraints(clist) specify constraints on transition probabilities

* Required options

fweights and pweights are allowed; see weight.

Description

mixmcm fits finite mixture of Markov chain models (MMCM) using conditional mlogit via the EM algorithm.
The command estimates the parameters of the transition probabilities of agents under the assumption of a finite mixture of homogeneous types in the population, with
each type following its own first-order Markovian process. That is, typically, agents are observed at several dates (or time periods) t={1...T} as located into a finite number of states (the modalities of depvar)
j={0...K} (with K>=2). State j=0 is arbitrarily chosen to indicate entry into or exit from the population. Each agent belongs to a specific homogeneous type g={1...G} (with G>=1). Agents' transitions from state
j={0...K} to state k={0...K} are thus observed but the type that agents belong to are not. mixmcm estimates the parameters specific to each homogeneous type
via the EM algorithm, treating the unobserved types of agents as missing information (see Mclachlan and Peel, 2004; Mclachlan and Krishman, 2007).
Transition probabilities may be specified as a function of explanatory variables (indepvars) through a multinomial logit specification. Type membership probabilities
may also be expressed as a function of explanatory variables using the fractional multinomial logit specification. Otherwise, type membership probabilities are estimated non-parametrically (see Saint-Cyr, 2017).

Options

id(varname) specifies the variable that identifies agents. mixmcm computes the probability of belonging to each specific homogeneous type for each id. id() is required.

timevar(varname) specifies the numeric variable that identifies dates on (or time periods during) which transitions occur. timevar() is required.

noconstant suppresses the constant term (or intercept) in the specification of transition probabilities. Specifying the noconstant option requires that at least one indepvar be specified.

entry(varlist) specifies the dependent and independent variables to enter the specification of entry probabilities. Specifying entry() requires that at least the dependent variable indicating the entry state be specified.

exitcode(name) indicates the modality of depvar which identifies the exit state.

ncomponents([#1 #2, selcrit(name) graph(namelist, twoway_options) save(filename, replace detail) force]) specifies options for the number of (unobserved) homogeneous types.

- #1 and #2 indicate the range for the number of components. If both #1 and #2 are specified, mixmcm will estimate #1 -- #2 MMCMs, starting from the model with #1 component(s) to the model with #2 components,
trying to identify the optimal number of components within this range based on the selection criterion specified in the sub-option selcrit(see below). Unless sub-option force is specified (see below), the estimation will stop automatically when the
optimal number of components is found, and the results will solely be displayed for this optimal number of components. If only #1 is specified, mixmcm will only estimate the parameters for this number of component(s), and the corresponding
results will be displayed. A standard (homogeneous) Markov chain model will be estimated if the specified number of components is #1=1. If ncomponents is not specified, a 2-component MMCM is estimated by default.

- selcrit(name) specifies the information criterion to be used to select the optimal number of components within the #1 to #2 range. The available information criteria are AIC, BIC, AIC3 or CAIC (the default).
See Andrews and Currim, 2003 for a discussion on using information criteria to select the optimal number of components.

- graph(namelist, twoway_options) specifies that a graph for the information criteria in namelist be drawn for the number of components in the #1 to #2 range. The
graph option thus requires that at least one information criterion among AIC, BIC, CAIC, AIC3 be specified in namelist. Users can manage the graph using standard twoway_options options.

- save(filename, replace detail) saves the information criteria for the numbers of components estimated within the #1 to #2 range in filemane. Specifying replace as a sub-option will overwrite an existing filename.
If detail is specified, as a save sub-option, the resulting parameters for all the estimated numbers of components will also be jointly saved.

- force indicates that the models should be estimated for every number of components within the #1 to #2 range, even though the optimal number of components is found to be smaller than #2 based on selcrit.
Therefore, estimations will contnue until #2 either way.

membership(varlist) specifies independent variables to enter the specification of component-membership probabilities. These variables must be constant over time for each agent.
The parametric form for the mixing distribution is the fmlogit which allows the dependent variable to lie between 0 and 1. Specifiying membership() requires that at least one explanatory variable be specified.
If membership() is not specified, component-membership probabilities will be estimated non-parametrically (see Train, 2008).

emiterate([lr(#1 #2, eps) sr(#1 #2) seed(numlist) emlog)]) specifies sub-options for the EM algorithm.

- lr(#1 #2, eps) specifies the number of long-run EMs (#1) to be performed, the maximum number of iterations (#2) to be used for each long-run EM, and the convergence criterion (eps) to stop iterations, respectively.
Defaults are 5 for #1, 100 for #2 and 0.0000001 for eps. eps is the tolerance used in the log-likelihood maximization: mixmcm declares convergence when the proportional increase in the log-likelihood over two consecutive
iterations is less than the specified eps.

- sr(#1 #2) specifies the number of short-run EMs (#1) and the maximum number of iterations for each short-run EM. Defaults are 5 for #1 and 5 for #2.

- seed(#) sets the pseudo-uniform random number seed. Initial parameters for the EM estimation are randomly chosen using the same seed. The default is 123456.
The seed is a local macro that does replace seeds that have been chosen by users out of the command.

- emlog displays the logs for the long-run EMs' iterations.

constraints(clist) lists the constraints that should be imposed on transition probabilities.
Each constraint listed in clist must be specified as: constraint # p_initialstate_finalstate = 0, where # is the number that identifies the constraint.
For now, transition probabilities can only be constrained to 0, and this constraint applies across all components.

Examples

The following examples use the mixmcmdata.dta database on French farms. The data are freely available online at RICA France micro-data.
We restricted the sample to farms which were present in the database for at least two consecutive years. We also kept only a few variables and renamed them to use in our examples. The 10 first lines of the mixmcm.dta database are:

idnum	year	surplus	istock icap debtr crop corp	educ	young	category
963 2000	36804 22896 76332 7.00 0 0 1 0 medium
963 2001 28861 17895 76331 6.40 0 0 1 0 medium
963 2002 30000 30194 76331 3.90 0 0 1 0 medium
963 2003 5159 0 76331 4.10 0 0 1 0 medium
1525 2006 58895 202919 283939 14.60 1 1 1 0 large
1525 2007 51726 101807 283939 22.10 1 1 1 0 vlarge
1525 2008 54940 176367 283939 27.20 1 1 1 1 vlarge
1525 2009 51883 198033 283939 20.00 1 1 1 1 vlarge
1525 2010 88685 183816 283939 18.10 1 1 1 1 vlarge
1534 2006 90051 124877 110557 51.10 1 1 1 0 vlarge

In the database, idnum and year are the farm identifier and the time variable, respectively. Variables surplus, istock, icap and debtr respectively are the Gross Operating
Surplus, initial stock and initial capital in Euros, and the debt ratio of the farm in percentage. The other (indicator) variables (crop = 1 if specialized in field crop production,
corp = 1 if corporate legal status, educ = 1 if farmer has higher education and young = 1 if farmer is under 41) were derived from original variables for our specific
examples. category, which will be used as depvar in mixmcm, was defined according to the original economic production potential pbuce variable and consists of three modalities,
namely medium (pbuce < 100000), large (with 100000 >= pbuce < 250000) and vlarge (with pbuce >= 250000).

1. First, we fit a two-component model with explanatory variables for transition probabilities:

. use mixmcm.dta, clear

. mixmcm category surplus istock crop corp, id(idnum) time(year)

2. Second, we again fit a two-component model but also account for entry and exit and include explanatory variables for entry and type-membership probabilities, and add constraints on some transition probabilities.

Identifying exits:

We consider farms that leave the sample before the last year of the panel (2010) as exits. A new modality named `exit' is thus added to the category variable.

. by idnum: generate _last = _n == _N

. drop if _last != 1

. keep idnum year

. by idnum: replace year=year+1 if _n == _N

. append using "mixmcm.dta"

. sort idnum year

{cmd:. replace category = "exit" if category == ""

Identifying entries:

We now consider farms that enter the sample after the first year of the panel (2000) as entries. We thus generate a new variable named entry_class that
collects the category in which farms are observed for the first time in the sample.

. by idnum: generate _first = _n == 1

. by idnum: generate str entry_class = "1" if _first == 1 & year != 2000

. levelsof category, local(catlevels)

. foreach cat of local catlevels {

2. replace entry_class = "`cat'" if category == "`cat'" & entry_class == "1"

3.}

. replace entry_class= "." if entry_class == ""

. drop _first

Computing the mean and mode of variables to enter the specification of type membership probabilities:

. by idnum: egen double meandebtr = mean(debtr)

. foreach v in educ young {

2. by idnum: egen double mode`v' = mode(`v')

3. by idnum: replace mode`v' = `v'[_N] if mode`v' == .

4.}

Specifying constraints on transition probabilities:

. constraint 1 p_medium_vlarge = 0

. constraint 2 p_vlarge_medium = 0

Model estimation:

. mixmcm category surplus istock crop corp, id(idnum) time(year) exit(exit) entry(entry_class icap corp) members(meandebt modeeduc modeyoung) const(1 2)

3. Finally, we search for the optimal number of components between 1 and 5 based on the CAIC information criterion, produce a graph and save the results for every tested component number.

. mixmcm category surplus istock crop corp, id(idnum) time(year) nc(1 5, graph(aic bic caic aic3, title("Fig. 1") ytitle("Information criteria") xtitle("Number of components") xlabel(1(1)5) scheme(sj) saving(figure.eps, replace)) save(icbtable, replace detail) force) emiter(lr(3 200, 0.000001) sr(3 5)) exit(exit) entry(entry_class icap corp) members(meandebtr modeeduc modeyoung) const(1 2)

Stored results

mixmcm stores the following in e():

Scalars

e(N_components) optimal number of homogeneous types

e(min_components) minimum number of homogeneous types estimate

e(max_components) maximum number of homogeneous types estimate

e(ll) log-likelihood

e(N) number of observations

e(N_id) number of agents identified by id()

e(k) number of free parameters estimated

e(aic) Akaike information criterion

e(aic3) restricted Akaike information criterion

e(bic) Bayesian information criterion

e(caic) consistent Akaike information criterion

e(converged) 1 if the EM algorithm converged, 0 otherwise

Macros

e(cmd) mixmcm command name

e(title) title in estimation output

e(cmdline) command line as it was written

e(id) name of the id() variable

e(depvar) name of the dependent variable

e(states) modalities of the dependent variable

e(exitcode) name of the exit state

e(indepvars) independent variables for transition probabilities

e(entry_var) name of the entry() variable

e(entry_indepvars) independent variables for entry probabilities

e(compvars) independent variables for component membership probabilities

e(mpf) functional form of the mixing distribution

e(selcrit) information criterion for the selection of the optimal number of components

e(seed) pseudo-uniform randomnumber seed

Matrices

e(b_tpm) vector of coefficients for entry and transition probabilities

e(V_tpm) covariance matrix of the coefficients for entry and transition probabilities

e(b_proba) vector of coefficients for component membership probabilities

e(V_tpm) covariance matrix of the coefficients for component membership coefficients

e(pi) vector of component shares

e(Cns_tpm) matrix of constraints

References

Andrews, R. L., & Currim, I. S. (2003). A comparison of segment retention criteria for finite mixture logit models. Journal of Marketing Research, 40(2), 235-243.

McLachlan, G., & Krishnan, T. (2007). The EM algorithm and extensions (Vol. 382). John Wiley & Sons.

McLachlan, G., & Peel, D. (2004). Finite mixture models. John Wiley & Sons.

Saint-Cyr, L. D. F. (2017). Accounting for unobserved farm heterogeneity in modelling structural change: evidence from France. UMR SMART-LERECO, AGROCAMPUS OUEST, INRA. PhD Disertation, 165 pages.

Train, K. E. (2008). EM algorithms for nonparametric estimation of mixing distributions. Journal of Choice Modelling, 1(1), 40-69.

Authors

Legrand D.F. SAINT-CYR and Laurent PIET

UMR SMART-LERECO -- AGROCAMPUS OUEST/INRA

Rennes, France

legrand.saint-cyr@inra.fr