*! version 2.0.0 25oct2016

*! version 1.0.4 02jun2016

*! version 1.0.3 25oct2015

*! version 1.0.2 11sep2015

*! version 1.0.1 03jul2015

*! version 1.0.0 01jun2015

Title

sfkk -- Endogenous stochastic frontier models in the style of Karakaplan and Kutlu (2013)

Contents

Syntax

Description

Options

Examples

Stored Results

Program Author

Recommended Citation

Acknowledgments

Disclaimer

Syntax

Estimation Syntax

sfkk depvar [indepvars] [if] [in] [weight] [, options]

Version Syntax

sfkk, version

Replay Syntax

sfkk [, level(#)]

Frontier
noconstant suppress constant term

production fit production frontier model; can be omitted

cost fit cost frontier model; default is production frontier model

Equations
endogenous(endovarlist) specify endogenous variables

instruments(ivarlist) specify instrumental variables

exogenous(exovarlist) specify included exogenous variables;
seldom used and can be omitted.

leaveout(lovarlist) specify included exogenous variables
to be left out; seldom used and can be omitted.

uhet(uvarlist[, noconstant]) explanatory
variables for inefficiency variance function; use noconstant
to suppress constant term

whet(wvarlist) explanatory
variables for idiosyncratic error variance function

Regression
initial(matname) specify initial values matrix

delve delve into maximization problem to find better initial values

fast(#) specify speed to explore approximate results faster

difficult use a different stepping algorithm in nonconcave regions

technique(algorithm_spec) specify maximization technique

iterate(#) perform maximum of # iterations; default is iterate(16000)

mlmodel(model_options) control ml model options; seldom used

mlmax(maximize_options) control ml maximize options; seldom used

Reporting
version display sfkk version and program author information; can be used in Version Syntax only

level(#) sets confidence level; default is level(95); can be used in Replay Syntax
or in mldisplay(display_options)

header display constraints header

timer display elapsed time to command completion

beep beep when command completes

compare display exogenous model regression results after displaying
endogenous model regression results

efficiency(effvar[, replace]) create efficiency variables
and summarize them in detail; use replace to replace contents of existing variables

test test endogeneity and report results

nicely display regression results nicely in single table

mldisplay(display_options) control ml display options; seldom used

All the variable lists above except depvar are allowed to contain factor variables.

Description

sfkk fits endogenous stochastic production or cost frontier models following
the methodology provided by Karakaplan and Kutlu (2013) . sfkk provides
estimators for the parameters of a linear model with a disturbance that is assumed to be
a mixture of two components: a measure of inefficiency which is strictly nonnegative and
a two-sided error term from a symmetric distribution. sfkk can handle endogenous
variables in the frontier and/or the inefficiency, and the sfkk
estimates outperform the standard frontier estimates that ignore endogeneity.
See Karakaplan and Kutlu (2013) for a detailed
explanation of their methodology and empirical analyses.

Options

Frontier

noconstant suppresses the constant term (intercept) in the frontier.

production specifies that the model to be fitted is a production frontier model. Since
the sfkk default is production, this option can be omitted.

cost specifies that the model to be fitted is a cost frontier model. The
sfkk default is production.

Equations

endogenous(endovarlist)
specifies that the variables in endovarlist are to be treated as endogenous.
If this option is not specified, sfkk assumes that the model is exogenous.

instruments(ivarlist)
specifies that the variables in ivarlist are to be used as instrumental variables to handle
endogeneity. If this option is not specified, sfkk assumes that the model is exogenous.

exogenous(exovarlist)
specifies that exovarlist is the complete list of included exogenous variables. The
sfkk default for the complete list of included exogenous variables is indepvars +
uvarist + wvarlist. Notice that depending on the model, exovarlist can be
different than indepvars + uvarist + wvarlist. For an illustration, please see the
examples below.
exogenous(exovarlist) cannot
be used with leaveout(lovarlist). exogenous(exovarlist)
option is seldom used and can safely be omitted.

leaveout(lovarlist)
specifies that the variables in lovarlist are to be taken out of the sfkk default list of
included exogenous variables which is indepvars + uvarist + wvarlist. Notice that
depending on the model, some variables such as functions of some included exogenous variables
can be left out of the
complete list of included exogenous variables. For an illustration, please see the
examples below. leaveout(lovarlist) cannot be used with
exogenous(exovarlist). leaveout(lovarlist)
option is seldom used and can safely be omitted.

uhet(uvarlist[, noconstant])
specifies that the inefficiency component is heteroskedastic,
with the variance function depending on a linear combination of
uvarlist. Specifying noconstant suppresses the
constant term from the variance function.

whet(wvarlist)
specifies that the idiosyncratic error component is heteroskedastic,
with the variance function depending on a linear combination of
wvarlist.

Regression

initial(matname)
specifies that matname is the initial value matrix.

delve provides a regression-based methodology to search for better initial values. The sfkk
default is to use ml search. delve is often successful in finding better
initial values. Using delve is recommended.

fast(#) provides a tolerance-based methodology to complete the regression faster. # can be specified
to take any value larger than 0. The regression completes faster with larger values of #, but larger values
of # result in less accurate findings. Experimenting with various # is suggested as different
values of # work better with different models. Using fast(#) is recommended
to explore the direction
of the maximization problem faster. However, in order to improve the accuracy of the findings,
it is highly recommended to avoid using fast(#) once the model is decided and
specification is finalized.

difficult specifies that the likelihood function is likely to be
difficult to maximize because of nonconcave regions. When the message "not
concave" appears repeatedly, ml's standard stepping algorithm may not be
working well. difficult specifies that a different stepping algorithm be
used in nonconcave regions. There is no guarantee that difficult will
work better than the default; sometimes it is better and sometimes it is
worse. difficult option should only be used when the default stepper
declares convergence and the last iteration is "not concave" or when the
default stepper is repeatedly issuing "not concave" messages and producing only
tiny improvements in the log likelihood.

technique(algorithm_spec) specifies how the likelihood function is to be
maximized. The following algorithms are allowed. For details, see
Gould, Pitblado, and Poi (2010).

technique(nr) specifies Stata's modified Newton-Raphson (NR)
algorithm.

technique(bhhh) specifies the Berndt-Hall-Hall-Hausman (BHHH)
algorithm. BHHH is only allowed with fast(#) specification.

technique(dfp) specifies the Davidon-Fletcher-Powell (DFP)
algorithm.

technique(bfgs) specifies the Broyden-Fletcher-Goldfarb-Shanno
(BFGS) algorithm.

The default is technique(bfgs).

Switching between algorithms is possible by specifying more than one algorithm in the
technique(.) option. By default, an algorithm is used for
five iterations before switching to the next algorithm. To specify a
different number of iterations, include the number after the technique in
the option. For example, specifying technique(bfgs 10 nr 1000)
requests that sfkk perform 10 iterations with the BFGS algorithm
followed by 1000 iterations with the NR algorithm, and then switch back
to BFGS for 10 iterations, and so on. The process continues until the
convergence or the maximum number of iterations is reached.

iterate(#) specifies the maximum number of iterations. When the number
of iterations equals #, the optimizer stops and
presents the current results. If convergence gets declared before this
threshold is reached, the optimizer would stop and present the optimized results. The default
value of # for sfkk is the current value of
maxiter, which is 16000.

mlmodel(model_options) can be used to control the ml model
options; seldom used

mlmax(maximize_options) can be used to control the ml max
options; seldom used

Reporting

version displays the version of sfkk installed on Stata, and the program author information.
This option can only be used in Version Syntax.

level(#) specifies the confidence level, as a percentage, for confidence
intervals. The default is level(95) or as set by set level. This option can be
used in Replay Syntax or in mldisplay(display_options)

header displays a summary of the model constraints in the beginning of the regression. header
provides a way to check the model specifications quickly while the estimation is running, or a guide to
distinguish different regression results that are kept in a single log file.

timer displays the total elapsed time sfkk took to complete.
The total elapsed time is measured
from the moment the command is entered to the moment the reporting of all findings is completed.

beep produces a beep when sfkk reports all of the findings. beep is
useful for multitasking.

compare estimates the specified model with exogeneity assumption and displays the regression
results after displaying the endogenous model regression results.

efficiency(effvar[, replace]) generates the production or cost efficiency variable
effvar_EN once the estimation is completed, and displays its summary statistics in detail. Notice that the option
automatically extends any specified variable name effvar with _EN. If compare
option is specified, efficiency option also generates effvar_EX, the production or cost efficiency
variable of the exogenous model, and displays its summary statistics. Specifying replace
replaces the contents of the existing effvar_EN and effvar_EX with the new efficiency values
from the current model.

test provides a method to test the endogeneity in the model. test tests the joint
significance of the components of the eta term, and reports the findings after displaying the regression
results. For more information about test see Karakaplan and Kutlu (2013) .

nicely displays the regression results nicely in a single table. nicely requires
estout, a user-written command by Ben Jann, to format some parts of the table,
and sfkk table style
resembles that of Karakaplan and Kutlu (2013) . nicely option checks
if estout package
is installed on Stata or not, and if not, then nicely option installs the package. If
compare option is specified,
nicely displays the exogenous and endogenous models with their corresponding equations and
statistics side by side in a single table for easy comparison. nicely estimates the production
or cost efficiency and tests endogeneity, and reports them in the table
even if efficiency(effvar) or test options are not specified.

mldisplay(display_options) can be used to control the ml display
options; seldom used

Examples

Endogenous Stochastic Cost Frontier Example

Setup

. use http://www.mukarakaplan.com/files/sfkkcost.dta, clear

. sfkk, version

Stochastic cost model with endogenous frontier and uhet variables

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) delve header timer beep

Examples of using fast(#), initial(matname),
efficiency(effvar), and test options

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) delve fast(1.5) timer beep

. matrix EST = e(b)

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) init(EST) eff(costef) test beep

Examples of using compare and nicely options

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) delve fast(10) compare beep

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) delve compare nicely beep

Examples of using exogenous(exovarlist) and leaveout(lovarlist) options

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) exo(x1 x3) header delve tech(bfgs nr)

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) leave(x2) header delve tech(bfgs nr)

Notice that the two examples above generate the same results. exogenous(exovarlist) and
leaveout(lovarlist) provide two different ways to specify the list of included exogenous
variables to be used. In these two models, even though x2 is used as an independent variable in the
frontier equation, it is not used as an independent variable in the endogenous variable equations
(z1 and z2).

Example of using noconstant option in the frontier

. sfkk y x1 x2 x3 z1, cost u(z2) en(z1 z2) i(iv1 iv2) delve nicely nocons

Endogenous Stochastic Production Frontier Example

Setup

. use http://www.mukarakaplan.com/files/sfkkprod.dta, clear

. summ

Exogenous stochastic production model

. sfkk y x1 x2 z1, prod u(z2)

Stochastic production model with endogenous frontier and uhet variables

. sfkk y x1 x2 z1, prod u(z2) en(z1 z2) i(iv1 iv2) delve nicely header beep

Stochastic production model with an endogenous frontier variable and no uhet specification

. sfkk y x1 x2 z1, prod en(z1) i(iv1) delve fast(1) nicely header

Notice that when uhet is not specified in the example above, the results table shows that uhet
included a constant by default. In the example below, uhet is specified with a variable but no
constant. Uhet specification would require at least one variable or the constant in uhet, and
specifying uhet( , nocons) to exclude uhet altogether from the model would give an error as the
inefficiency component is a necessary part of the model.

Example of using noconstant option in uhet(uvarlist)

. sfkk y x1 x2 z1, prod u(z2, nocons) en(z1 z2) i(iv1 iv2) delve nicely tech(bfgs nr)

Examples of using difficult, technique(algorithm_spec), and iterate(#)

. sfkk y x1 x2 z1, u(z2) en(z1 z2) i(iv1 iv2) diff compare nicely timer

. sfkk y x1 x2 z1, u(z2) en(z1 z2) i(iv1 iv2) tech(nr 5 bfgs 10) compare nicely timer

. sfkk y x1 x2 z1, u(z2) en(z1 z2) i(iv1 iv2) iter(30) compare nicely timer

Notice that in the last example above, because of iterate(30) specification,
the optimizer stops prematurely and presents the results before the convergence is achieved. Hence, the
presented results are significantly different than that in the two preceding examples.

Examples of using mlmodel(model_options),
mlmax(maximize_options), mldisplay(display_options), and
the Replay Syntax

. sfkk y x1 x2 z1, prod u(z2) en(z1 z2) i(iv1 iv2) fast(0.5) tech(nr bhhh bfgs dfp) mlmod(vce(robust))

. sfkk y x1 x2 z1, prod u(z2) en(z1 z2) i(iv1 iv2) diff mlmax(trace gradient)

. sfkk y x1 x2 z1, prod u(z2) en(z1 z2) i(iv1 iv2) fast(0.1) tech(dfp 4 bhhh 8 nr 4) diff compare mldis(coeflegend)

. sfkk, level(80)

Examples of using weight and factor variables

. gen count = 1

. replace count = 2 if y > 0.6

. tab count

. sfkk y x1 x2 z1 [fweight = count], prod u(z2) en(z1 z2) i(iv1 iv2) nicely

. gen type = 1 + round(uniform())

. tab type

. sfkk y x1 x2 z1 i2.type, prod u(z2 i2.type) en(z1 z2) i(iv1 iv2) nicely compare diff

Example from the U.S. K-12 Education Sector

Setup

. use http://www.mukarakaplan.com/files/sfkkedu.dta, clear

. sfkk expend enroll enroll2 scores prices body, cost u(hhi) en(scores hhi) i(streams unemp) delve compare nicely header beep timer tech(dfp 25 bfgs 25)

For details about the datasets and results, see Karakaplan (2016) .

Stored Results

sfkk stores the following in e():

Scalars

e(effmed) median efficiency

e(effmean) mean efficiency

e(etatestX2) eta test chi-squared

e(etatestp) eta test p value

e(sigma_v) standard deviation of V_i

e(p) significance

e(chi2) chi-squared

e(df_m) model degrees of freedom

e(k_eq_model) number of equations in overall model test

e(ll) log likelihood

e(rc) return code

e(converged) 1 if converged, 0 otherwise

e(k_dv) number of dependent variables

e(k_eq) number of equations in e(b)

e(k) number of parameters

e(ic) number of iterations

e(N) number of observations

e(rank) rank of e(V)

Macros

e(_estimates_name) name of stored results

e(estimates_title) title of stored results

e(cmdbase) base command

e(cmd) name of user command

e(cmdline) command as typed

e(het) heteroskedastic components

e(function) production or cost

e(dist) distribution assumption for U_i

e(chi2type) type of model chi-squared test

e(opt) type of optimization

e(predict) program used to implement predict

e(u_hetvar) varlist in uhet()

e(vcetype) title used to label Std. Err.

e(vce) vcetype specified in vce()

e(title) title in estimation output

e(user) name of likelihood-evaluator program

e(ml_method) type of ml method

e(technique) maximization technique

e(which) max or min; whether optimizer is to perform
maximization or minimization

e(depvar) name of dependent variable(s)

e(properties) b V

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of the estimators

e(ilog) iteration log (up to 20 iterations)

e(gradient) gradient vector

Functions

e(sample) marks estimation sample

sfkk stores the following in estimates memory:

Estimates

ModelEN stored estimates of endogenous model

ModelEX stored estimates of exogenous model if compare option is specified

Note that if compare option is specified, ereturn list
would list the results from the last specification, which is the exogenous model. In order to retrieve
the stored results from the endogenous model, estimates restore ModelEN can be used.

Program Author

Dr. Mustafa Ugur Karakaplan
E-mail: mukarakaplan@yahoo.com
Webpage: www.mukarakaplan.com

For comments, suggestions, or questions about sfkk, please send
an email to me.

Recommended Citations

The following two citations are recommended for referring to the sfkk program package
and the underlying econometric methodology:

Karakaplan, Mustafa U. (2016) "Estimating Endogenous Stochastic Frontier Models in Stata."
Forthcoming. The Stata Journal.
Also available at www.mukarakaplan.com

Karakaplan, Mustafa U. and Kutlu, Levent (2013) "Handling Endogeneity in Stochastic Frontier Analysis."
Available at www.mukarakaplan.com

Acknowledgments

I would like to thank Levent Kutlu, Isabel Canette, Ben Jann, and Kit Baum for their amazing support.

Disclaimer

sfkk is not an official Stata command. It is a third-party command
programmed by Mustafa U. Karakaplan as a free contribution
to the research society. By choosing to download, install and use the sfkk package,
users assume all the liability for any sfkk package related risk. If you encounter
any problems with the sfkk package, or if you have comments, suggestions, or questions,
please send an email to Mustafa U. Karakaplan at
mukarakaplan@yahoo.com