Hi All,
I'm using Stata/IC 13.1.
I'm having an odd issue with setting initial values using 'ml init'. My code works just fine as it is, taking starting values from a user-written programme 'sfcross', but when I try to tweak it slightly so that starting values are taken from Stata's built-in frontier command, I'm getting an error message, and I can't figure out the reason for this. The full code is:
Note that when i change
to
everything works as intended. Here is the section of code where I find the error message, after using 'set trace on':
Can anyone figure this out? Thanks,
Alex
I'm using Stata/IC 13.1.
I'm having an odd issue with setting initial values using 'ml init'. My code works just fine as it is, taking starting values from a user-written programme 'sfcross', but when I try to tweak it slightly so that starting values are taken from Stata's built-in frontier command, I'm getting an error message, and I can't figure out the reason for this. The full code is:
Code:
program cnsf2, eclass
version 13.1
if !replay() {
syntax varlist(numeric fv ts) [if] [in] [, Level(cilevel) LCLASS(integer 2) COST PRODuction]
local s = -1
if "`cost'"=="" local s = 1
global cost_s `s'
global class_num `lclass'
marksample touse
gettoken yvar xvars : varlist
local mlmodel_list /lnsigma_v1
forval i = 2/`lclass' {
local mlmodel_list `mlmodel_list' /lnsigma_v`i'
}
local probs = `lclass'-1
forval i = 1/`probs' {
local mlmodel_list `mlmodel_list' /logprob`i'
}
local diparm_list diparm(lnsigma_v1, exp label(sigma_v1) prob)
forval i = 2/`lclass' {
local diparm_list `diparm_list' diparm(lnsigma_v`i', exp label(sigma_v`i') prob)
}
forval i = 1/`probs' {
local diparm_list `diparm_list' diparm(logprob`i', invlogit label(prob`i') prob)
}
ml model d1 cnsf2_ll (mu:`yvar'=`xvars') /lnsigma_u `mlmodel_list', title(Stoch. frontier contaminated normal/half normal model) diparm(lnsigma_u, exp label(sigma_u) prob) `diparm_list'
quietly{
//net install sfcross, all from(http://www.econometrics.it/stata) replace
//sfcross `yvar' `xvars', cost d(h)
frontier `yvar' `xvars', cost d(h)
scalar _b_cons=_b[_cons]
forval i = 1/`lclass' {
scalar _lnsigma_v`i' = ln(e(sigma_v))+ln(`i'^2/`lclass')
}
forval i = 1/`probs' {
scalar _logprob`i' = -ln(1/(1/2)^`i'-1)
}
scalar _lnsigma_u = ln(e(sigma_u))
foreach x in `xvars'{
scalar _b_`x' = _b[`x']
}
foreach x in `xvars'{
ml init mu:`x' = `=_b_`x''
}
ml init mu:_cons = `=_b_cons'
local mlinit_list /lnsigma_v1=`=_lnsigma_v1'
forval i = 2/`lclass' {
local mlinit_list `mlinit_list' /lnsigma_v`i'=`=_lnsigma_v`i''
}
forval i = 1/`probs' {
local mlinit_list `mlinit_list' /logprob`i'=`=_logprob`i''
}
ml init /lnsigma_u=`=_lnsigma_u' `mlinit_list'
}
}
ml search
ml maximize, difficult
tempname b V y
matrix `b' = e(b)
matrix `V' = e(V)
ereturn post `b' `V', esample(`touse')
ereturn local predict "cnsf2_p"
ereturn local cmd "cnsf2"
global ML_y1 `yvar'
end
Code:
//net install sfcross, all from(http://www.econometrics.it/stata) replace
//sfcross `yvar' `xvars', cost d(h)
frontier `yvar' `xvars', cost d(h)
Code:
net install sfcross, all from(http://www.econometrics.it/stata) replace
sfcross `yvar' `xvars', cost d(h)
//frontier `yvar' `xvars', cost d(h)
Code:
- if "`subcmd'" == "init" {
= if "init" == "init" {
- Init `0'
= Init mu:lnq = .9658624953033792
------------------------------------------------------ begin mopt.Init ---
- tempname b0
- mata: Mopt_get_b0()
model not defined
-------------------------------------------------------- end mopt.Init ---
exit
}
--------------------------------------------------------------- end mopt ---
exit
}
------------------------------------------------------------------- end ml ---
Alex
