代码拉取完成,页面将自动刷新
cap program drop regcmd
program define regcmd,eclass
version 14
syntax [anything], policy(varlist) id(varname) [*]
_parse_policy `0'
local policy `"`r(policy)'"'
local id `"`r(id)'"'
local cmd `"`r(cmd)'"'
preserve
randpolicy, policy(`policy') id(`id')
qui `cmd'
restore
end
cap program drop _parse_policy
program define _parse_policy,rclass
syntax [anything(name=exp_list equalok)] ///
[fw iw pw aw] [if] [in], policy(varlist) id(varname) [*]
tokenize `"`0'"', p(",")
local cmd `1', `options'
return local policy `policy'
return local id `id'
return local cmd `cmd'
end
* version 2.0, 7 Jun 2021
* by Kerry Du
cap program drop randpolicy
program define randpolicy
version 14
syntax, id(varname) Policy(varlist numeric)
tempvar tt rn
qui bys `id': gen `tt'=_n
tempname PP
sort `id' `tt'
qui putmata `PP' = (`policy'),replace
qui gen double `rn'=uniform() if `tt'==1
qui bys `id' (`tt'): replace `rn'=`rn'[_n-1] if _n>1
sort `rn' `tt'
qui getmata (`policy')= `PP',replace
cap mata mata drop `PP'
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。