📄 brr.ado
字号:
*! version 1.1.13 01apr2005
program brr, eclass sortpreserve
version 9
local version : di "version " string(_caller()) ":"
// Stata 8 syntax
capture _on_colon_parse `0'
if c(rc) | `"`s(after)'"' == "" {
if !c(rc) {
local 0 `"`s(before)'"'
}
// replay output
if replay() {
if "`e(prefix)'`e(vce)'" != "svybrr" {
error 301
}
svy `0'
exit
}
}
`version' BRR `0'
end
program BRR, eclass
version 9
local version : di "version " string(_caller()) ":"
// <my_stuff> : <command>
_on_colon_parse `0'
local command `"`s(after)'"'
local 0 `"`s(before)'"'
// quick check for -nodrop- option
syntax [anything(name=exp_list equalok)] ///
[fw iw pw aw] [if] [in] [, ///
COEF /// for -logistic-
noDROP ///
Level(passthru) ///
FORCE ///
* /// other options
]
_get_eformopts, soptions eformopts(`options') allowed(__all__)
local options `"`s(options)'"'
local efopt = cond(`"`s(opt)'"'=="",`"`s(eform)'"',`"`s(opt)'"')
if "`weight'" != "" {
local wgt [`weight'`exp']
}
// parse the command and check for conflicts
`version' _prefix_command brr `wgt' `if' `in' , ///
svy checkvce `coef' `efopt' `level': `command'
if `"`r(vce)'"' != "" {
di as err "option vce() not allowed"
exit 198
}
while inlist(`"`s(cmdname)'"', "svy", "brr") {
if `"`s(cmdname)'"' == "svy" & `"`s(cmdargs)'"' != "" {
_svy_check_vce `vcetype'
if `"`s(vce)'"' != "brr" {
error 198
}
}
if `"`wgt'"' == "" & `"`s(wgt)'"' != "" {
local wgt `"[`s(wgt)']"'
}
local if `"`s(if)'"'
local in `"`s(in)'"'
local efopt `"`s(efopt)'"'
local options `"`options' `s(cmdopts)'"'
if `"`s(rest)'"' == "" {
svy `wgt' `if' `in', ///
`efopt' `cluster' `level' `options'
exit
}
`version' _prefix_command brr `wgt' `if' `in' , ///
svy checkvce `efopt' `cluster' `level' ///
checkcluster `s(rest)'
}
// note: weights are only allowed from -svyset-
local version `"`s(version)'"'
local cmdname `"`s(cmdname)'"'
local cmdargs `"`s(anything)'"'
local cmdif `"`s(if)'"'
local cmdin `"`s(in)'"'
local cmdopts `"`s(options)'"'
local rest `"`s(rest)'"'
local efopt `"`s(efopt)'"'
local command `"`s(command)'"'
local level `"`s(level)'"'
if `"`efopt'"' != "" & !inlist(`"`:list retok exp_list'"', "", "_b") {
local efopt
}
// -_svy_check_cmdopts- resets -s()-
_svy_check_cmdopts `cmdname', `cmdopts'
local first `"`s(first)'"'
local cmdlog `"`s(log)'"'
local exclude jackknife jknife statsby
if `:list cmdname in exclude' ///
| ("`force'" == "" & substr("`cmdname'",1,3) == "svy") {
di as err "`cmdname' is not supported by brr"
exit 199
}
if "`s(replay)'" != "" {
if "`e(cmdname)'" != "`cmdname'" {
error 301
}
svy, `options' `cmdopts' `efopt' level(`level') `rest'
exit
}
is_svysum `cmdname'
local is_sum = r(is_svysum)
// now check the rest of the options
local 0 `", `options'"'
syntax [, ///
Hadamard(name) ///
FAY(numlist >=0 <= 2 max=1) ///
noDOTS ///
SAving(string) ///
DOUBle /// not documented
MSE MSE1 ///
NOIsily /// "prefix" options
TRace ///
REJECT(string asis) ///
noHeader /// Display options
noLegend ///
notable ///
Verbose ///
TItle(string asis) ///
SUBpop(passthru) /// -svy- options
noADJust ///
`svyopts' ///
]
// MSE1 exists just in case the `mse' option is specified twice due to
// -svyset-
if `is_sum' {
Check4Over, `cmdopts'
local hasover `"`s(hasover)'"'
}
// check expressions
tempname touseN npop
tempvar subuse touse wvar
mark `touse' `cmdif' `cmdin'
_svy_setup `touse' `subuse', ///
cmdname(`cmdname') ///
svy ///
brr ///
`subpop' ///
`hasover' ///
nosubdrop ///
// blank
if "`r(wtype)'" != "" {
local wtype `"`r(wtype)'"'
local wexp `"`r(wexp)'"'
local wt [`wtype'`wexp']
quietly gen double `wvar' `wexp'
local wgt [`wtype'=`wvar']
}
else {
quietly gen double `wvar' = `touse'
local wgt
}
if "`mse'" == "" {
local mse `r(mse)'
}
local posts `"`r(poststrata)'"'
local postw `"`r(postweight)'"'
local subpop `"`r(subpop)'"'
local srssub `r(srssubpop)'
if `"`subpop'`srssub'"' != "" {
if "`srssub'" != "" {
local subopt ", srssubpop"
}
local subopt `"subpop(`subpop'`subopt')"'
}
if "`r(fpc1)'" != "" {
di as err "FPC is not allowed with BRR"
exit 459
}
local brrw `r(brrweight)'
if "`brrw'" != "" {
if "`hadamard'" != "" {
di as txt ///
"note: using hadamard() option instead of replicate weights"
}
else if "`fay'" != "" {
di as err ///
"option fay() is not allowed with replicate weights"
exit 198
}
local creps : word count `brrw'
}
if "`brrw'" == "" {
if "`hadamard'" == "" {
di as err ///
"option hadamard() required when brrweights are not svyset"
exit 198
}
local strata `r(strata1)'
local psu `r(su1)'
if "`strata'" == "" {
di as err "brr requires strata to be svyset"
exit 459
}
tempvar strid psuid
sort `strata' `psu'
quietly by `strata' : gen `strid' = _n == 1
quietly count if `strid' == 1
local nstrata = r(N)
quietly replace `strid' = sum(`strid')
if "`psu'" == "" {
quietly by `strata' : ///
gen `psuid' = _n
}
else {
quietly by `strata' `psu' : ///
gen `psuid' = _n == 1
quietly by `strata' : ///
replace `psuid' = sum(`psuid')
}
capture by `strata' : ///
assert `psuid'[_N] == 2
if c(rc) {
di as err "brr requires that all strata have 2 PSUs"
exit 459
}
if "`fay'" == "" {
local fay 0
}
if `fay' == 1 {
di as err "option fay(1) is not allowed"
exit 198
}
_hadamard_verify `hadamard', optname(hadamard)
local creps = r(order)
if `nstrata' > `creps' {
di as err ///
"too few columns in matrix specified in hadamard() option"
exit 198
}
}
if `"`posts'"' != "" {
tempname postwvar
svygen post double `postwvar' `wgt' ///
if `touse' == 1, ///
posts(`posts') postw(`postw')
local npost = r(N_poststrata)
local pstropt pstrwvar(`postwvar') ///
posts(`posts') postw(`postw')
local uwvar `postwvar'
if "`wtype'" == "" {
local wgt [pw=`uwvar']
}
else {
local wgt [`wtype'=`uwvar']
}
}
else {
local uwvar `wvar'
}
sum `uwvar', mean
scalar `npop' = r(sum)
quietly count if `touse' == 1
scalar `touseN' = r(N)
if "`trace'" != "" {
local noisily noisily
local traceon set trace on
local traceoff set trace off
}
if "`cmdlog'" != "" {
local noisily noisily
}
if "`noisily'" != "" {
local dots nodots
}
tempvar order
quietly gen long `order' = _n
local sortvars : sortedby // restore sort order later
// preliminary parse of <exp_list>
_prefix_explist `exp_list', stub(_brr_)
local eqlist `"`s(eqlist)'"'
local idlist `"`s(idlist)'"'
local explist `"`s(explist)'"'
local eexplist `"`s(eexplist)'"'
_prefix_note `cmdname', `dots'
if "`noisily'" != "" {
di "brr: First call to `cmdname' with data as is:" _n
di as inp `". `command'"'
}
local props : properties `cmdname'
local svyr svyr
// run the command using the entire dataset
_prefix_clear, e r
if `:list svyr in props' & `"`exp_list'"' == "" {
`traceon'
capture noisily quietly `noisily' `version' ///
svy, subpop(if `subuse', `srssub') ///
vce(linearized) : `cmdname' `cmdargs' ///
if `touse', `cmdopts' `rest'
`traceoff'
if e(singleton) {
// -brr- can do nothing more, so just
// report results and exit
svy
exit
}
}
else {
`traceon'
capture noisily quietly `noisily' `version' ///
`cmdname' `cmdargs' ///
`wgt' if `subuse', `cmdopts' `rest'
`traceoff'
}
local rc = c(rc)
// error occurred while running on entire dataset
if `rc' {
_prefix_run_error `rc' brr `cmdname'
}
// check for rejection of results from entire dataset
if `"`reject'"' != "" {
_prefix_reject brr `cmdname' : `reject'
local reject `"`s(reject)'"'
}
if `"`cmdname'"' == "mlogit" {
_prefix_mlogit, `cmdopts'
local cmdopts `"`s(options)'"'
}
// check e(sample)
_prefix_check4esample brr `cmdname'
if "`drop'" == "" {
local keepesample `"`s(keep)'"'
}
// ignore s(diwarn)
// determine default <exp_list>, or generate an error message
if `"`exp_list'"' == "" {
_prefix_explist, stub(_brr_) edefault
local eqlist `"`s(eqlist)'"'
local idlist `"`s(idlist)'"'
local explist `"`s(explist)'"'
local eexplist `"`s(eexplist)'"'
}
// expand eexp's that may be in eexplist, and build a matrix of the
// computed values from all expressions
tempname b
_prefix_expand `b' `explist', ///
stub(_brr_) ///
eexp(`eexplist') ///
colna(`idlist') ///
coleq(`eqlist') ///
// blank
local k_eq `s(k_eq)'
local k_exp `s(k_exp)'
local k_eexp `s(k_eexp)'
local K = `k_exp' + `k_eexp'
local k_extra `s(k_extra)'
local names `"`s(enames)' `s(names)'"'
local express `"`s(explist)'"'
local eexpress `"`s(eexplist)'"'
forval i = 1/`K' {
local exp`i' `"`s(exp`i')'"'
}
forval i = 1/`K' {
if missing(`b'[1,`i']) {
di as err ///
`"statistic `exp`i'' evaluated to missing in full sample"'
exit 322
}
}
if `is_sum' & `k_exp' == 0 & "`eexpress'" == "(_b)" {
// speed things up with the -novariance-
_prefix_checkopt NOVARiance, `cmdopts'
if `"`noisily'`s(novariance)'"' == "" {
local novar " novar"
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -