楼主: bu妥先生
4156 5

[数据管理求助] 算年报披露日后30个交易日股票回报率均值,要怎么编程? [推广有奖]

  • 0关注
  • 0粉丝

已卖:43份资源

大专生

48%

还不是VIP/贵宾

-

威望
0
论坛币
2267 个
通用积分
0.3600
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
564 点
帖子
18
精华
0
在线时间
66 小时
注册时间
2015-6-12
最后登录
2019-7-25

楼主
bu妥先生 发表于 2018-7-5 16:17:58 |AI写论文
100论坛币
大家也都知道不同的上市公司年报披露日是不同的,股票只在非周末非节假日交易;
我现在就是需要计算每家上市公司年报披露日后30个交易日股票回报率的均值,这在stata或python中怎么实现?
我举个栗子:表1是每家上市公司年报披露日期
                     表2是每家上市公司2018-1-19至2018-6-22每天的股票回报率

  从表1中可知,000001股票的披露日是2018-3-15,我们需要从表2中找到000001,找到2018-3-15这个日期,然后向后数30个交易日,计算平均值。

表1


表2

得到平均值是0.0012672,就是表1第三列所求




2.xlsx
下载链接: https://bbs.pinggu.org/a-2504744.html

5.98 MB

1.xlsx

62.87 KB

最佳答案

kyoukai 查看完整内容

Here is a solution, change the file location before using these codes. ------------------------------------------- *Pre-requisition: ssc install rangestat ssc install egenmore *Merge two datasheets from excel format, assuming no duplicates in each datasheet. Keep only stock identifiers are inclusive in the two sheets. clear all import excel "C:\Users\Downloads\1.xlsx", sheet("Sheet1") firs ...
关键词:stata python
已有 1 人评分经验 论坛币 收起 理由
葫芦娃大王 + 10 + 3 鼓励积极发帖讨论

总评分: 经验 + 10  论坛币 + 3   查看全部评分

沙发
kyoukai 发表于 2018-7-5 16:17:59
Here is a solution, change the file location before using these codes.
-------------------------------------------
*Pre-requisition:
ssc install rangestat
ssc install egenmore
*Merge two datasheets from excel format, assuming no duplicates in each datasheet. Keep only stock identifiers are inclusive in the two sheets.
clear all
import excel "C:\Users\Downloads\1.xlsx", sheet("Sheet1") firstrow
drop in 1
save "C:\Users\Desktop\masterfile.dta", replace
import excel "C:\Users\Downloads\2.xlsx", sheet("Sheet1") firstrow clear
drop in 1
merge m:1 Stkcd using "C:\Users\Desktop\masterfile.dta"
keep if _merge==3
drop _merge
*Convert data information from string type to time variable that Stata can recognises
gen date1 = date( Annodt , "MDY")
gen date2=date( date ,"MDY")
format date1 date2 %td
*Sort all observations by stock identifier and date
sort Stkcd date2
*For each stock, assgin serial number of date (datenum), obtain target date (target) as the indicator of earning announcement date, then have the time window before/after the date
by Stkcd: gen datenum = _n
by Stkcd: gen target = datenum if date2 == date1
egen td = min(target), by(Stkcd)
gen diff = datenum-td
*Obtain rollowing-window mean of ILLIQ for each stock, time interval set as 30 days. Check if "000001" matches as mannual outcome.
destring ILLIQ,replace
rangestat (mean) ILLIQ , interval( diff 1 30) by(Stkcd)
replace Annodt日后30交易日股票回报率平均值= ILLIQ_mean
keep if Stkcd=="000001" & target!=.
----------------------------------------------------
Comments welcome
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Brilliantenkey + 1 + 1 + 1 精彩帖子
逐梦的太阳 + 5 + 5 热心帮助其他会员

总评分: 论坛币 + 5  学术水平 + 1  热心指数 + 6  信用等级 + 1   查看全部评分

藤椅
bu妥先生 发表于 2018-8-5 15:43:02
kyoukai 发表于 2018-7-5 16:17
Here is a solution, change the file location before using these codes.
---------------------------- ...
完美运行啦,厉害厉害!十分感谢热心帮助!不过最后一句命令直接  keep if target!=. 就可以了吧?

板凳
kyoukai 发表于 2018-8-6 09:23:47
bu妥先生 发表于 2018-8-5 15:43
完美运行啦,厉害厉害!十分感谢热心帮助!不过最后一句命令直接  keep if target!=. 就可以了吧?
这是为了只留下你给出数据的那个结果方便你比对。你自己用的时候删掉就行了。

报纸
bu妥先生 发表于 2018-8-6 09:34:25
kyoukai 发表于 2018-8-6 09:23
这是为了只留下你给出数据的那个结果方便你比对。你自己用的时候删掉就行了。
Nice!谢谢啦~

地板
zhjh200915 发表于 2019-1-17 22:01:15
正好需要,非常感谢

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 21:12