1 Star 0 Fork 2

wxq8888wxq/statamacroe

forked from kerrydu/statamacroe 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
chaintobase.ado 901 Bytes
一键复制 编辑 原始数据 按行查看 历史
kerrydu 提交于 2021-07-09 19:39 . 0
cap program drop chaintobase
program define chaintobase, sortpreserve
version 14
syntax varname(numeric), gen(string) t(varname) [id(varname) base(numlist max=1) ]
if `"`id'"'!=""{
qui tab `id', nofreq
local nid=r(r)
local N=_N
if mod(`N',`nid')!=0{
noi display as error "{bf:chaintobase} needs strongly balanced panel, use {bf:tsfill, full} to rectangularize your data."
exit
}
}
else{
tempvar id
qui gen `id'=1
}
sort `t'
if "`base'"=="" local base = `t'[1]
qui gen `gen'=`varlist'
qui bys `id' (`t'): replace `gen'=100 if _n==1
qui bys `id' (`t'): replace `gen'=`gen'[_n-1]*`varlist'/100 if _n>1
tempvar baseindex2 baseindex
qui bys `id' (`t'): egen `baseindex2' = mean(`gen') if `t'==`base'
qui bys `id' (`t'): egen `baseindex' = total(`baseindex2')
qui bys `id' (`t'): replace `gen'=`gen'/`baseindex'
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/wxq8888wxq/statamacroe.git
[email protected]:wxq8888wxq/statamacroe.git
wxq8888wxq
statamacroe
statamacroe
master

搜索帮助