楼主: 黃河泉
2846 4

[程序分享] 如何让指数成分股历史数据完整! [推广有奖]

大师

53%

还不是VIP/贵宾

-

威望
3
论坛币
34526 个
通用积分
56166.6181
学术水平
3539 点
热心指数
3700 点
信用等级
2923 点
经验
308806 点
帖子
14520
精华
12
在线时间
7406 小时
注册时间
2016-7-9
最后登录
2024-11-4

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
根据这里的问题:https://bbs.pinggu.org/thread-6816710-1-1.html,(感谢) Clyde Schechter 提供作法:
  1. // https://www.statalist.org/forums/forum/general-stata-discussion/general/1474659-construct-a-complete-list-of-index-components-over-different-periods
  2. // https://bbs.pinggu.org/thread-6816710-1-1.html
  3. clear
  4. input str22 Indexcd str13 Chgsmp01 str19(Chgsmp02 Chgsmp03) str13 Chgsmp04
  5. "000016" "2004-01-02" "600000" "浦发银行" "1"
  6. "000016" "2004-01-02" "600004" "白云机场" "1"
  7. "000016" "2004-01-02" "600006" "东风汽车" "1"
  8. "000016" "2004-01-02" "600008" "首创股份" "1"
  9. "000016" "2004-01-02" "600009" "上海机场" "1"
  10. "000016" "2004-01-02" "600011" "华能国际" "1"
  11. "000016" "2004-01-02" "600015" "华夏银行" "1"
  12. "000016" "2004-01-02" "600016" "民生银行" "1"
  13. "000016" "2004-01-02" "600018" "上港集箱" "1"
  14. "000016" "2004-01-02" "600019" "宝钢股份" "1"
  15. "000016" "2004-01-02" "600026" "中海发展" "1"
  16. "000016" "2004-01-02" "600028" "中国石化" "1"
  17. "000016" "2004-01-02" "600029" "南方航空" "1"
  18. "000016" "2004-01-02" "600030" "中信证券" "1"
  19. "000016" "2004-01-02" "600033" "福建高速" "1"
  20. "000016" "2004-01-02" "600036" "招商银行" "1"
  21. "000016" "2004-01-02" "600038" "哈飞股份" "1"
  22. "000016" "2004-01-02" "600050" "中国联通" "1"
  23. "000016" "2004-01-02" "600098" "广州控股" "1"
  24. "000016" "2004-01-02" "600100" "清华同方" "1"
  25. "000016" "2004-01-02" "600104" "上海汽车" "1"
  26. "000016" "2004-01-02" "600171" "上海贝岭" "1"
  27. "000016" "2004-01-02" "600221" "海南航空" "1"
  28. "000016" "2004-01-02" "600350" "山东基建" "1"
  29. "000016" "2004-01-02" "600569" "安阳钢铁" "1"
  30. "000016" "2004-01-02" "600591" "上海航空" "1"
  31. "000016" "2004-01-02" "600597" "光明乳业" "1"
  32. "000016" "2004-01-02" "600601" "方正科技" "1"
  33. "000016" "2004-01-02" "600602" "广电电子" "1"
  34. "000016" "2004-01-02" "600609" "金杯汽车" "1"
  35. "000016" "2004-01-02" "600637" "广电信息" "1"
  36. "000016" "2004-01-02" "600642" "申能股份" "1"
  37. "000016" "2004-01-02" "600643" "爱建股份" "1"
  38. "000016" "2004-01-02" "600649" "原水股份" "1"
  39. "000016" "2004-01-02" "600652" "爱使股份" "1"
  40. "000016" "2004-01-02" "600664" "哈药集团" "1"
  41. "000016" "2004-01-02" "600705" "北亚集团" "1"
  42. "000016" "2004-01-02" "600717" "天津港"    "1"
  43. "000016" "2004-01-02" "600795" "国电电力" "1"
  44. "000016" "2004-01-02" "600805" "悦达投资" "1"
  45. "000016" "2004-01-02" "600808" "马钢股份" "1"
  46. "000016" "2004-01-02" "600811" "东方集团" "1"
  47. "000016" "2004-01-02" "600812" "华北制药" "1"
  48. "000016" "2004-01-02" "600832" "东方明珠" "1"
  49. "000016" "2004-01-02" "600839" "四川长虹" "1"
  50. "000016" "2004-01-02" "600863" "内蒙华电" "1"
  51. "000016" "2004-01-02" "600887" "伊利股份" "1"
  52. "000016" "2004-01-02" "600895" "张江高科" "1"
  53. "000016" "2004-01-02" "600900" "长江电力" "1"
  54. "000016" "2004-01-02" "600688" "上海石化" "1"
  55. "000016" "2004-07-01" "600002" "齐鲁石化" "1"
  56. "000016" "2004-07-01" "600005" "武钢股份" "1"
  57. "000016" "2004-07-01" "600020" "中原高速" "1"
  58. "000016" "2004-07-01" "600021" "上海电力" "1"
  59. "000016" "2004-07-01" "600038" "哈飞股份" "2"
  60. "000016" "2004-07-01" "600098" "广州控股" "2"
  61. "000016" "2004-07-01" "600205" "山东铝业" "1"
  62. "000016" "2004-07-01" "600221" "海南航空" "2"
  63. "000016" "2004-07-01" "600597" "光明乳业" "2"
  64. "000016" "2004-07-01" "600863" "内蒙华电" "2"
  65. "000016" "2005-01-03" "600210" "紫江企业" "1"
  66. "000016" "2005-01-03" "600500" "中化国际" "1"
  67. "000016" "2005-01-03" "600637" "广电信息" "2"
  68. "000016" "2005-01-03" "600652" "爱使股份" "2"
  69. "000016" "2005-01-03" "600660" "福耀玻璃" "1"
  70. "000016" "2005-01-03" "600664" "哈药集团" "2"
  71. "000016" "2005-01-03" "600780" "通宝能源" "1"
  72. "000016" "2005-01-03" "600805" "悦达投资" "2"
  73. "000016" "2005-01-03" "600811" "东方集团" "2"
  74. "000016" "2005-01-03" "600879" "火箭股份" "1"
  75. "000016" "2005-07-01" "600006" "东风汽车" "2"
  76. "000016" "2005-07-01" "600008" "首创股份" "2"
  77. "000016" "2005-07-01" "600098" "广州控股" "1"
  78. "000016" "2005-07-01" "600188" "兖州煤业" "1"
  79. "000016" "2005-07-01" "600320" "振华港机" "1"
  80. "000016" "2005-07-01" "600350" "山东基建" "2"
  81. "000016" "2005-07-01" "600519" "贵州茅台" "1"
  82. "000016" "2005-07-01" "600609" "金杯汽车" "2"
  83. "000016" "2005-07-01" "600705" "北亚集团" "2"
  84. "000016" "2005-07-01" "600797" "浙大网新" "1"
  85. "000016" "2006-01-04" "600021" "上海电力" "2"
  86. "000016" "2006-01-04" "600027" "华电国际" "1"
  87. "000016" "2006-01-04" "600058" "五矿发展" "1"
  88. "000016" "2006-01-04" "600177" "雅戈尔"    "1"
  89. "000016" "2006-01-04" "600309" "烟台万华" "1"
  90. "000016" "2006-01-04" "600428" "中远航运" "1"
  91. "000016" "2006-01-04" "600569" "安阳钢铁" "2"
  92. "000016" "2006-01-04" "600591" "上海航空" "2"
  93. "000016" "2006-01-04" "600643" "爱建股份" "2"
  94. "000016" "2006-01-04" "600812" "华北制药" "2"
  95. "000016" "2006-04-24" "600002" "齐鲁石化" "2"
  96. "000016" "2006-04-24" "600269" "赣粤高速" "1"
  97. end

  98. * dataex

  99. // Clyde Schechter
  100. //    SAVE A SEPARATE FILE FOR EACH CHGMSP01
  101. capture program drop one_date
  102. program define one_date
  103.     local date = Chgsmp01[1]
  104.     save `date', replace
  105.     exit
  106. end

  107. runby one_date, by(Chgsmp01) status

  108. //    NOW UPDATE EACH FILE ONE DATE AT A TIME
  109. levelsof Chgsmp01, local(dates)
  110. local n_files: word count `dates'

  111. forvalues i = 2/`n_files' {
  112.     local change_file: word `i' of `dates'
  113.     local last_file: word `=`i'-1' of `dates'
  114.     use `last_file', clear
  115.     append using `change_file'
  116.     by Chgsmp02 (Chgsmp04), sort: assert (_N == 2) == (Chgsmp04[_N] == "2")
  117.     by Chgsmp02 (Chgsmp04): drop if _N == 2
  118.     replace Chgsmp01 = `"`change_file'"'
  119.     assert _N == 50
  120.     save `"`change_file'"', replace
  121. }

  122. //    NOW APPEND THEM ALL
  123. clear
  124. foreach d of local dates {
  125.     append using `d'
  126. }
  127. assert _N == 50*`n_files' & Chgsmp04 == "1"
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:000016 600098 600664 600812 600811

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 精彩帖子

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

沙发
黃河泉 在职认证  发表于 2018-12-14 10:14:30 |只看作者 |坛友微信交流群
该问题乃在原始资料在第一期提供完整之 50 成分股,第二期之后,只提供相对于上一期之增减成分股,没有提供所有新的 (或包括一些旧的) 成分股!

使用道具

藤椅
清、涟。 发表于 2018-12-14 10:38:41 |只看作者 |坛友微信交流群
谢谢黄老师!非常感谢。也谢谢Clyde Schechter。

使用道具

板凳
黃河泉 在职认证  发表于 2018-12-14 10:49:40 |只看作者 |坛友微信交流群
清、涟。 发表于 2018-12-14 10:38
谢谢黄老师!非常感谢。也谢谢Clyde Schechter。
没错,Clyde Schechter 帮过我很多忙,今年六月多,他来台湾,我跟我太太请他们家人在台湾大学吃饭,聊得很愉快!

使用道具

报纸
清、涟。 发表于 2018-12-14 11:50:14 |只看作者 |坛友微信交流群
哈哈哈。黄老师真的很热心,在论坛上看过您很多精彩的回答。

使用道具

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

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-11-6 07:28