Skip to content
GitLab
菜单
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录/注册
切换导航
菜单
打开侧边栏
zhu hongbing
TwoSort
提交
376a4393
未验证
提交
376a4393
编辑于
12月 06, 2018
作者:
zhbsis
提交者:
GitHub
12月 06, 2018
浏览文件
Add files via upload
上级
7196d0bf
变更
2
Hide whitespace changes
Inline
Side-by-side
CalculationVW.ado
0 → 100644
浏览文件 @
376a4393
capture
program
drop
CalculationVW
//-定义计算加权收益率函数
program
define
CalculationVW
version
14.0
syntax
varlist
(
max
=
2
),
groupVar
(
string
)
time
(
string
)
*-调用变量分割函数
DivideVar
`varlist'
*-计算主体程序
tempvar
value_return
sum_v
value_return_sum_v
gen
`value_return'
=
$y
*
$x
bys
`groupVar'
`time'
:
egen
`sum_v'
=
sum
(
$x
)
gen
`value_return_sum_v'
=
`value_return'
/
`sum_v'
bys
`groupVar'
`time'
:
egen
VW_
$y
=
sum
(
`value_return_sum_v'
)
end
Group2.ado
0 → 100644
浏览文件 @
376a4393
capture
program
drop
Group2
//-定义分组函数
capture
program
drop
Group2
program
define
Group2
version
14.0
syntax
,
groupVar
(
string
)
groupName
(
string
)
groupN
(
integer
)
time
(
string
)
tempvar
n1
n2
n3
n4
n5
sort
`time'
`groupVar'
by
`time'
:
gen
`n1'
=
_n
if
`groupVar'
!=.
// 按time生成_n
by
`time'
:
egen
`n2'
=
max
(
`n1'
)
// 取给定time中的最大_n,记为n2
gen
`n3'
=
`n2'
/
`groupN'
// n2/分组数=每组间距,记为n3
gen
`n4'
=
round
(
`n3'
)
// 对n3取整处理,记为n4
gen
`n5'
=
`n3'
-
`n4'
// n3-n4,记为n5
*replace `n3' = `n3'+1 if `n5'>0 // n5大于0则n3+1 旧方法
replace
`n4'
=
`n4'
+1
if
`n5'
>
0
// n5大于0则n3+1 新方法
gen
`groupName'
=
.
forvalues
i
=
1
(
1
)
`groupN'
{
local
j
=
`i'
-1
*gen cutPoint`i'=`n3'*`i' // 旧切割点定义方法
gen
cutPoint
`i'
=
`n4'
*
`i'
// 新定义方法
if
(
`i'
==
1
){
replace
`groupName'
=
`i'
if
`n1'
<=
cutPoint
`i'
}
if
(
`i'
!=
1
){
replace
`groupName'
=
`i'
if
`n1'
<=
cutPoint
`i'
&
`n1'
>
cutPoint
`j'
}
}
drop
cutPoint
*
end
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录