1 Star 0 Fork 20

fangyb/gtfpch

forked from kerrydu/gtfpch 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sbmeff.ado 13.14 KB
一键复制 编辑 原始数据 按行查看 历史
kerrydu 提交于 2020-09-15 21:14 . merge lgtfpch&lsbmeff + compiled in V16
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
*! version 2.0.1
* 2020-8-15, remove sup opt
*! version 2.0
* By Kerry Du & Daoping Wang, 8 Aug 2020
capture program drop sbmeff
program define sbmeff, rclass
version 16
if strpos(`"`0'"',":")==0{ // Tone(2001) SBM without undesriable outputs
sbmeffnu2 `0'
exit
}
gettoken word 0 : 0, parse(" =:,")
while `"`word'"' != ":" & `"`word'"' != "=" {
if `"`word'"' == "," | `"`word'"'=="" {
error 198
}
local invars `invars' `word'
gettoken word 0 : 0, parse("=:,")
}
unab invars : `invars'
gettoken word 0 : 0, parse(" =:,")
while `"`word'"' != ":" & `"`word'"' != "=" {
if `"`word'"' == "," | `"`word'"'=="" {
error 198
}
local gopvars `gopvars' `word'
gettoken word 0 : 0, parse(" =:,")
}
unab gopvars : `gopvars'
*syntax varlist [if] [in], dmu(varname) [Time(varname) SEQuential VRS SAVing(string) maxiter(numlist integer >0 max=1) tol(numlist max=1)]
syntax varlist [if] [in], Dmu(varname) [Time(varname) rf(varname) ///
BIennial SEQuential GLObal VRS ///
SAVing(string) WINdow(numlist intege max=1 >=1) ///
maxiter(numlist integer >0 max=1) tol(numlist max=1) ]
preserve
marksample touse
markout `touse' `invars' `gopvars'
local bopvars `varlist'
local invars: list uniq invars
local gopvars: list uniq gopvars
local bopvars: list uniq bopvars
confirm numeric var `invars' `gopvars' `bopvars'
local comvars: list invars & gopvars
if !(`"`comvars'"'==""){
disp as error "`comvars' should not be specified as input and desriable output simultaneously."
error 498
}
local comvars: list invars & bopvars
if !(`"`comvars'"'==""){
disp as error "`comvars' should not be specified as input and undesriable output simultaneously."
error 498
}
local comvars: list gopvars & bopvars
if !(`"`comvars'"'==""){
disp as error "`comvars' should not be specified as desriable and undesriable outputs simultaneously."
error 498
}
local ninp: word count `invars'
local ngo: word count `gopvars'
local nbo: word count `bopvars'
local rts=0
if "`vrs'"!=""{
local rts=1
}
if "`maxiter'"==""{
local maxiter=-1
}
if "`tol'"==""{
local tol=-1
}
local techtype "contemporaneous production technology"
//local techtype "contemporaneous"
if `"`time'"'==""& "`sequential'`biennial'`window'"==""{
local techtype "global production technology"
local global global
}
if "`global'"=="" {
if "`time'"==""{
disp as error "For biennial/window/sequential/ model, time() should be specified."
error 498
}
}
if "`maxiter'"==""{
local maxiter=-1
}
if "`tol'"==""{
local tol=-1
}
if "`global'"!=""{
if "`sequential'"!=""{
disp as error "global and sequential cannot be specified together."
error 498
}
if "`window'"!=""{
disp as error "global and window() cannot be specified together."
error 498
}
if "`biennial'"!=""{
disp as error "global and biennial cannot be specified together."
error 498
}
local techtype "global production technology"
}
if "`sequential'"!=""{
if "`window'"!=""{
disp as error "sequential and window() cannot be specified together."
error 498
}
if "`biennial'"!=""{
disp as error "sequential and biennial cannot be specified together."
error 498
}
local techtype "sequential production technology"
}
if "`window'"!=""{
if "`biennial'"!=""{
disp as error "biennial and window() cannot be specified together."
error 498
}
local techtype "window(`window') production technology"
}
if "`biennial'"!=""{
local techtype "biennial production technology"
}
qui mata mata mlib index
qui keep `invars' `gopvars' `bopvars' `dmu' `time' `touse' `rf'
qui gen Row=_n
label var Row "Row #"
qui keep if `touse'
qui gen double TE=.
label var TE "Technical Efficiency"
foreach v in `invars' `gopvars' `bopvars'{
qui gen double S_`v'=.
label var S_`v' `"Slack:`v'"'
local slackvars `slackvars' S_`v'
}
tempvar tvar dmu2
if `"`time'"'!="" {
qui egen `tvar'=group(`time')
qui egen `dmu2'=group(`dmu')
}
else{
qui gen `tvar'=1
qui gen `dmu2'=_n
}
sort Row `dmu2' `tvar'
tempvar touse2 touse3 touse4
qui gen byte `touse2'=1
if "`rf'"!=""{
qui replace `touse2'=(`rf'!=0) if !missing(`rf')
}
markout `touse2' `invars' `opvars' `badvars' `rf'
qui gen byte `touse3'=0
qui gen byte `touse4'=`touse'
local data `invars' `gopvars' `bopvars'
if "`global'"!=""{
mata: _sbmeff("`data'",`ninp',`ngo',"`touse'", "`touse2'","TE `slackvars'",`rts',`maxiter',`tol')
}
qui su `tvar'
local tmax=r(max)
if "`sequential'"!=""{
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'<=`t' & `touse2'==1)
mata: _sbmeff("`data'",`ninp',`ngo',"`touse4'", "`touse3'","TE `slackvars'",`rts',`maxiter',`tol')
}
}
if "`biennial'"!=""{
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'>=`t' & `tvar'<=`t'+1 & `touse2'==1)
mata: _sbmeff("`data'",`ninp',`ngo',"`touse4'", "`touse3'","Dval `slackvars'",`rts',`maxiter',`tol')
}
}
if "`window'"!=""{
local band=(`window'-1)/2
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'>=`t'-`band' & `tvar'<=`t'+`band' & `touse2'==1)
mata: _sbmeff("`data'",`ninp',`ngo',"`touse4'", "`touse3'","TE `slackvars'",`rts',`maxiter',`tol')
}
}
if "`global'`sequential'`biennial'`window'"==""&"`time'"!=""{
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'==`t' & `touse2'==1)
mata: _sbmeff("`data'",`ninp',`ngo',"`touse4'", "`touse3'","TE `slackvars'",`rts',`maxiter',`tol')
}
}
order Row `dmu' `time' TE `slackvars'
keep Row `dmu' `time' TE `slackvars'
disp _n(2) " SBM Efficiency Results:"
disp " (Row: Row # in the original data; TE: Efficiency Score; S_X: Slack of X)"
//disp " S_X : Slack of X"
*format TE `slackvars' %9.4f
list Row `dmu' `time' TE `slackvars', sep(0)
//disp _n
if `"`saving'"'!=""{
save `saving'
gettoken filenames saving:saving, parse(",")
local filenames `filenames'.dta
disp _n `"Estimated Results are saved in `filenames'."'
}
return local file `filenames'
restore
end
///////////////////////////////////////////////////////////////////////////////
capture program drop sbmeffnu2
program define sbmeffnu2, rclass
version 16
gettoken word 0 : 0, parse(" =:,")
while `"`word'"' != ":" & `"`word'"' != "=" {
if `"`word'"' == "," | `"`word'"'=="" {
error 198
}
local invars `invars' `word'
gettoken word 0 : 0, parse("=:,")
}
unab invars : `invars'
*syntax varlist [if] [in], dmu(varname) [Time(varname) SEQuential VRS SAVing(string) maxiter(numlist integer >0 max=1) tol(numlist max=1)]
syntax varlist [if] [in], Dmu(varname) [Time(varname) rf(varname) ///
BIennial SEQuential GLObal VRS ///
SAVing(string) WINdow(numlist intege max=1 >=1) ///
maxiter(numlist integer >0 max=1) tol(numlist max=1) ]
local gopvars `varlist'
unab gopvars : `gopvars'
preserve
marksample touse
markout `touse' `invars' `gopvars'
local invars: list uniq invars
local gopvars: list uniq gopvars
confirm numeric var `invars' `gopvars'
local comvars: list invars & gopvars
if !(`"`comvars'"'==""){
disp as error "`comvars' should not be specified as input and desriable output simultaneously."
error 498
}
local ninp: word count `invars'
local ngo: word count `gopvars'
local rts=0
if "`vrs'"!=""{
local rts=1
}
if "`maxiter'"==""{
local maxiter=-1
}
if "`tol'"==""{
local tol=-1
}
local techtype "contemporaneous production technology"
//local techtype "contemporaneous"
if `"`time'"'==""& "`sequential'`biennial'`window'"==""{
local techtype "global production technology"
local global global
}
if "`global'"=="" {
if "`time'"==""{
disp as error "For biennial/window/sequential/ model, time() should be specified."
error 498
}
}
if "`maxiter'"==""{
local maxiter=-1
}
if "`tol'"==""{
local tol=-1
}
if "`global'"!=""{
if "`sequential'"!=""{
disp as error "global and sequential cannot be specified together."
error 498
}
if "`window'"!=""{
disp as error "global and window() cannot be specified together."
error 498
}
if "`biennial'"!=""{
disp as error "global and biennial cannot be specified together."
error 498
}
local techtype "global production technology"
}
if "`sequential'"!=""{
if "`window'"!=""{
disp as error "sequential and window() cannot be specified together."
error 498
}
if "`biennial'"!=""{
disp as error "sequential and biennial cannot be specified together."
error 498
}
local techtype "sequential production technology"
}
if "`window'"!=""{
if "`biennial'"!=""{
disp as error "biennial and window() cannot be specified together."
error 498
}
local techtype "window(`window') production technology"
}
if "`biennial'"!=""{
local techtype "biennial production technology"
}
qui mata mata mlib index
qui keep `invars' `gopvars' `dmu' `time' `touse' `rf'
qui gen Row=_n
label var Row "Row #"
qui keep if `touse'
qui gen double TE=.
label var TE "Technical Efficiency"
foreach v in `invars' `gopvars' {
qui gen double S_`v'=.
label var S_`v' `"Slack:`v'"'
local slackvars `slackvars' S_`v'
}
tempvar tvar dmu2
if `"`time'"'!="" {
qui egen `tvar'=group(`time')
qui egen `dmu2'=group(`dmu')
}
else{
qui gen `tvar'=1
qui gen `dmu2'=_n
}
sort Row `dmu2' `tvar'
tempvar touse2 touse3 touse4
qui gen byte `touse2'=1
if "`rf'"!=""{
qui replace `touse2'=(`rf'!=0) if !missing(`rf')
}
markout `touse2' `invars' `opvars' `rf'
* markout `touse2' `invars' `opvars'
qui gen byte `touse3'=0
qui gen byte `touse4'=`touse'
local data `invars' `gopvars'
if "`global'"!=""{
mata: _sbm("`data'",`ninp',`ngo',"`touse'", "`touse2'","TE `slackvars'",`rts',`maxiter',`tol')
}
qui su `tvar'
local tmax=r(max)
if "`sequential'"!=""{
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'<=`t' & `touse2'==1)
mata: _sbm("`data'",`ninp',`ngo',"`touse4'", "`touse3'","TE `slackvars'",`rts',`maxiter',`tol')
}
}
if "`biennial'"!=""{
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'>=`t' & `tvar'<=`t'+1 & `touse2'==1)
mata: _sbm("`data'",`ninp',`ngo',"`touse4'", "`touse3'","Dval `slackvars'",`rts',`maxiter',`tol')
}
}
if "`window'"!=""{
local band=(`window'-1)/2
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'>=`t'-`band' & `tvar'<=`t'+`band' & `touse2'==1)
mata: _sbm("`data'",`ninp',`ngo',"`touse4'", "`touse3'","TE `slackvars'",`rts',`maxiter',`tol')
}
}
if "`global'`sequential'`biennial'`window'"==""&"`time'"!=""{
forv t=1/`tmax'{
qui replace `touse4'=(`tvar'==`t' & `touse')
qui replace `touse3'=(`tvar'==`t' & `touse2'==1)
mata: _sbm("`data'",`ninp',`ngo',"`touse4'", "`touse3'","TE `slackvars'",`rts',`maxiter',`tol')
}
}
order Row `dmu' `time' TE `slackvars'
keep Row `dmu' `time' TE `slackvars'
*format TE `slackvars' %9.4f
disp _n(2) " SBM Efficiency Results:"
disp " (Row: Row # in the original data; TE: Efficiency Score; S_X: Slack of X)"
//disp " S_X : Slack of X"
list Row `dmu' `time' TE `slackvars', sep(0)
//disp _n
if `"`saving'"'!=""{
save `saving'
gettoken filenames saving:saving, parse(",")
local filenames `filenames'.dta
disp _n `"Estimated Results are saved in `filenames'."'
}
return local file `filenames'
restore
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fangyebing/gtfpch.git
git@gitee.com:fangyebing/gtfpch.git
fangyebing
gtfpch
gtfpch
master

搜索帮助