1 Star 0 Fork 2

kerrydu/statamacroe

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
regcmd.ado 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
kerrydu 提交于 2021-07-13 15:44 . regcmd
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/kerrydu/statamacroe.git
[email protected]:kerrydu/statamacroe.git
kerrydu
statamacroe
statamacroe
master

搜索帮助