*! version 1.0 06DEC2016

help for randcoefBarriga Cabanillas, Michler, Michuda, Tjernström

Title

randcoef -- Estimates CRE and CRC models following
Tavneet Suri's paper: "Selection and Comparative Advantage in Technology Adoption," Econometrica, Vol. 79, No. 1 (January, 2011), 159-209.

Syntax

Basic syntax

randcoef
(depvar1 depvar2 depvar3...) [if]
, choice(indepvar1 indepvar2 indepvar3 ...)
[options]

Description

randcoef
estimates both the CRE (Correlated Random Effects) (default) and the CRC (Correlated Random Coefficients) models allowing several weighting matrices for
the latter. The command uses the number of dependent variables to know how many years the CRE
or CRC model contains and use the appropriate restriction matrix.
The command's syntax requires the order of both the outcome and choice variables to be set chronologically. This is important since the order in the regressions must match the restriction
matrices pre-wired in the command. This is true, except for the CRE model where the user can specify it Restrictions.
The set up of the CRC model requieres interactions between the choice variables. These interactions are automatically created by the command.
For a more thorough overview of the theory behind the estimation, please read Suri (2011).

by is not allowed.

fweights are not allowed

Options

Required options

choice (varlist) It must contain the variable of interest organized in chronological order. In the case of the CRC model, interactions SHOULD NOT be included since they are created
automatically by the program. These variables must defined as dummies.

General options

method(CRE, CRC) Determines the method to be used: CRE (default) or CRC.

controls (varlist) Allows adding controls to the underlying SUR regression.

showreg By default the program does not show the SUR regression's output for faster computation and to avoid displaying innecesary information.
This option allows the user to see the SUREG output.

CRE model options

matrix A matrix containing the problem's restrictions can be specified in case the
user wants to input the restriction matrix manually (perhaps for changing the order of coefficients). Note that the
restriction's order is important since it must match the order in which the parameters of interest
are inputted in the SUR regressions.

CRC model options

For this model the matrix option is not allowed. The restriction matrices are preprogrammed for up to five year panels and
are automatically chosen depending on the number of dependent variables. Additionally, the CRC model involves the creation of interactions
between the adoption variables, these interactions are created automatically within the program. See examples.

endogenous(varlist) Allows for endogenous variables to be added to the
CRC estimation. This must be a dummy variable. The interactions needed between the choice variables and the endogenous variables are
automatically created.

keep During the estimation of the CRC model the interactions needed for the choice variables, as well as the endogenous variables
(if specified) are deleted after the program is run. This option allows preserving those interactions after the estimation.
Note that if specified, running the command several times requires dropping those variables

weighting(string) Chooses the weighting matrix to be used.

OMD (default) Optimal Minumum Distance: the inverse of the variance-covariance matrix of the reduced form
estimates.

EWMD Equally Weighted Minimum Distance: Uses the identity matrix.

DWMD Diagonally Weighted Minimum Distance: Uses the optimal matrix, but with zeroes
on the off-diagonals.

Examples

. randcoef lny2008 lny2010 , choice(h_2008 h_2010) meth(CRE) (click to run)

Estimates the CRE model for a two year panel.

Note that the magnitudes of the parameters of the "structural" parameters are: beta = 2, lambda_1 = 4, lambda_2 = 3

. randcoef lny2008 lny2010, choice(h_2008 h_2010) meth(CRC) weighting(DWMD) (click to run)

Estimates the CRC model for a two year panel. In this case, the interactions for the choice variable
are automatically created. Given that keep is not used, these interactions are not available after the estimation. The weighting of the OMD used
the Diagonally Weighted Minimum Distance.
Note that the magnitudes of the parameters of the "structural" parameters are: beta = 2, lambda_1 = 4, lambda_2 = 3, lambda_3 = 2, phi = 2

. randcoef lny2008 lny2010, choice(h_2008 h_2010) endogenous(e_2008 e_2010) meth(CRC) (click to run)

Estimates the CRC model for a two year panel and an extra endogenous variable. The weighting of the OMD used the inverse of the variance-covariance
matrix of the reduced form estimates.
Note that the magnitudes of the parameters of the "structural" parameters are: beta = 2, lambda_1 = 4, lambda_2 = 3,
lambda_3 = 2, lambda_3 = 2, lambda_3 = 2, lambda_3 = 2, lambda_3 = 2, lambda_3 = 2,
lambda_4 = 6, lambda_5 = 7, lambda_6 = 8, lambda_7 = 9, lambda_8 = 11, lambda_9 = 12, lambda_10 = 13, lambda_11 = 14,
phi = 2 and rho = 1

Restrictions

The following represents an example of the restrictions the CRC model uses on the Optimal Minimun Distance estimation. This is performed in mata. It is extremely important that the names of the
functions: (derivat33) and (myeval); as well as the name of the vectors: (gtheta) , (theta) and (derivat33) are not changed. However, their dimensions
can be adapted to the needs of the model estimated. In this case, the command uses a DWMD weighting matrix, and we have chosen to keep the generated interactions after
estimation.

//-------------------------------- Mata code ------------------------

version 10
mata:

mata clear
mata drop *()
mata set matalnum off
mata set mataoptimize on
mata set matafavor speed

// Explicitly set dimensions for the number of colums on
// the INITIAL VALUES ON THE theta_0 vector for the maximization
// Line 341 randcoef do file

n_col = 5

// Defines the funtion to take derivatices from. Notice that it
// is the same as in the previous function

void myeval(todo, theta , param , V, omd , S , H)
{
real colvector diff

gtheta=J(1,n_col_gtheta,1)

gtheta[1]=theta[1]*(1+theta[5])+theta[4]+theta[5]*(-0.7827869*theta[1]-0.8970037*theta[2]-0.7494407*theta[3])
gtheta[2]=theta[2]
gtheta[3]=theta[3]*(1+theta[5])+(theta[5]*theta[2])
gtheta[4]=theta[1]
gtheta[5]=theta[2]*(1+theta[5])+theta[4]+theta[5]*(-0.7827869*theta[1,1]-0.8970037*theta[2]-0.7494407*theta[3])
gtheta[6]=theta[3]*(1+theta[5])+(theta[5]*theta[1])

diff = param-gtheta'
omd= (diff)'*V*(diff)

}

void derivat33( theta , gtheta )
{
gtheta = J(1,n_col_gtheta,.)

gtheta[1]=theta[1]*(1+theta[5])+theta[4]+theta[5]*(-0.7827869*theta[1]-0.8970037*theta[2]-0.7494407*theta[3])
gtheta[2]=theta[2]
gtheta[3]=theta[3]*(1+theta[5])+(theta[5]*theta[2])
gtheta[4]=theta[1]
gtheta[5]=theta[2]*(1+theta[5])+theta[4]+theta[5]*(-0.7827869*theta[1,1]-0.8970037*theta[2]-0.7494407*theta[3])
gtheta[6]=theta[3]*(1+theta[5])+(theta[5]*theta[1])

}

end

// -------------------------------- end Mata code ------------------------

(Go up to Syntax )

Authors

Oscar Barriga Cabanillas

obarriga@ucdavis.edu

Jeffrey D. Michler

jmichler@illinois.edu

Aleksandr Michuda

amichuda@ucdavis.edu

Emilia Tjernström

tjernstroem@wisc.edu