833 0

[面板数据求助] 滚动回归要求最大最小窗口 [推广有奖]

  • 0关注
  • 0粉丝

已卖:1份资源

大专生

3%

还不是VIP/贵宾

-

威望
0
论坛币
499 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
90 点
帖子
4
精华
0
在线时间
83 小时
注册时间
2021-9-16
最后登录
2025-12-23

楼主
经管之家账号1230 发表于 2024-7-11 22:06:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
求问大神,现在我需要一个进行回归分析拟合回归系数,需要滚动回归,论文中要求最小24个月最大60个月,我的理解是从当月往回回溯最多60个月的数据(如果有的话),没有的话最少回溯24个月的数据,但是如何操作呢,我想要的是reg ret rm_rf r__rf ,求α β1 β2 残差,以及ER=预测值,IR=实际值-残差下面放上示例数据
论文原文‘The regression is estimated for each firm on a rolling annual basis using historical monthly returns data from the CRSP database.We require at least 24 months of historical data and use up to 60 months of data in the estimation. Expected returns are computed using the estimated factor loadings and realized factor returns 1 year hence.’
  1. clear
  2. input str3 sic3 long permno int year byte month double(ret rm_rf r__rf)
  3. "399" 10000 1986  2 -.257143  .0713    .05508100000000001
  4. "399" 10000 1986  3  .365385  .0488   .041192000000000006
  5. "399" 10000 1986  4 -.098592 -.0131   .010939999999999995
  6. "399" 10000 1986  5 -.222656  .0462    .03129399999999998
  7. "399" 10000 1986  6 -.005025  .0103  .0028870000000000007
  8. "399" 10000 1986  7 -.080808 -.0645   -.07832800000000001
  9. "399" 10000 1986  8 -.615385  .0607   .018668999999999998
  10. "399" 10000 1986  9 -.057143  -.086              -.063571
  11. "399" 10000 1986 10 -.242424  .0466   .019176999999999996
  12. "399" 10000 1986 11      .06  .0117  -.010163000000000002
  13. "399" 10000 1986 12 -.377358 -.0327              -.039509
  14. "399" 10000 1987  1 -.212121  .1247    .11336499999999997
  15. "399" 10000 1987  2        0  .0439    .07031199999999997
  16. "399" 10000 1987  3 -.384615  .0164   .031582999999999986
  17. "399" 10000 1987  4   -.0625 -.0211   -.02210700000000001
  18. "399" 10000 1987  5 -.066667  .0011              -.003201
  19. "399" 10000 1987  6        .  .0394   .016686999999999994
  20. "131" 10005 1986  2 -.333333  .0713    .05508099999999969
  21. "131" 10005 1986  3     .125  .0488   .041192000000000215
  22. "131" 10005 1986  4  .055556 -.0131   .010940000000000037
  23. "131" 10005 1986  5        0  .0462   .031294000000000044
  24. "131" 10005 1986  6 -.526316  .0103  .0028869999999999833
  25. "131" 10005 1986  7 -.555556 -.0645   -.07832800000000023
  26. "131" 10005 1986  8      .25  .0607   .018668999999999988
  27. "131" 10005 1986  9       .4  -.086   -.06357099999999982
  28. "131" 10005 1986 10        0  .0466    .01917699999999995
  29. "131" 10005 1986 11 -.142857  .0117  -.010162999999999978
  30. "131" 10005 1986 12        0 -.0327   -.03950899999999987
  31. "131" 10005 1987  1  .666667  .1247     .1133649999999998
  32. "131" 10005 1987  2       .1  .0439    .07031199999999994
  33. "131" 10005 1987  3        0  .0164    .03158300000000001
  34. "131" 10005 1987  4        0 -.0211  -.022107000000000047
  35. "131" 10005 1987  5  .454545  .0011              -.003201
  36. "131" 10005 1987  6    -.125  .0394   .016686999999999952
  37. "131" 10005 1987  7  .714286  .0385   .030522999999999793
  38. "131" 10005 1987  8    -.375  .0352   .009843999999999922
  39. "131" 10005 1987  9 -.266667 -.0259  -.020376000000000002
  40. "131" 10005 1987 10 -.181818 -.2324    -.2782479999999991
  41. "131" 10005 1987 11        0 -.0777   -.05435000000000002
  42. "131" 10005 1987 12        0  .0681               .022165
  43. "131" 10005 1988  1  .111111  .0421    .07449199999999978
  44. "131" 10005 1988  2        0  .0475   .055664999999999784
  45. "131" 10005 1988  3        0 -.0227    .03128999999999983
  46. "131" 10005 1988  4      -.2  .0056    .00941599999999995
  47. "131" 10005 1988  5    -.125 -.0029  -.022770999999999996
  48. "131" 10005 1988  6        0  .0479    .04276799999999986
  49. "131" 10005 1988  7  .285714 -.0125  -.004803000000000002
  50. "131" 10005 1988  8        0 -.0331  -.030900999999999942
  51. "131" 10005 1988  9 -.333333   .033   .010751000000000056
  52. "131" 10005 1988 10        0  .0115   -.01758100000000001
  53. "131" 10005 1988 11        0 -.0229   -.04218399999999993
  54. "131" 10005 1988 12        0  .0149               .012572
  55. "131" 10005 1989  1        0   .061    .05662400000000019
  56. "131" 10005 1989  2        0 -.0225  -.003112000000000007
  57. "131" 10005 1989  3        0  .0157   .011360000000000068
  58. "131" 10005 1989  4 -.166667  .0433   .022388999999999937
  59. "131" 10005 1989  5        0  .0335    .01715399999999993
  60. "131" 10005 1989  6        0 -.0135  -.014843999999999979
  61. "131" 10005 1989  7        0   .072   .024017000000000066
  62. "131" 10005 1989  8      -.2  .0144   .011225999999999924
  63. "131" 10005 1989  9     -.25 -.0076 -.0009680000000000044
  64. "131" 10005 1989 10        0 -.0367   -.05673600000000004
  65. "131" 10005 1989 11  .333333  .0103  -.012704999999999985
  66. "131" 10005 1989 12        0  .0116   -.01847500000000002
  67. "131" 10005 1990  1        0 -.0785  -.052107999999999766
  68. "131" 10005 1990  2     -.25  .0111   .009733999999999956
  69. "131" 10005 1990  3        0  .0183   .014915000000000001
  70. "131" 10005 1990  4        0 -.0336   -.03501599999999988
  71. "131" 10005 1990  5        0  .0842   .038873000000000005
  72. "131" 10005 1990  6        0 -.0109 -.0009410000000000061
  73. "131" 10005 1990  7        0  -.019   -.03253100000000005
  74. "131" 10005 1990  8        0 -.1015   -.11552000000000022
  75. "131" 10005 1990  9  .666667 -.0612   -.08646799999999985
  76. "131" 10005 1990 10      -.4 -.0192   -.06395499999999987
  77. "131" 10005 1990 11        0  .0635    .02976799999999989
  78. "131" 10005 1990 12        0  .0246  -.010526000000000008
  79. "131" 10005 1991  1  .666667  .0469    .07897499999999999
  80. "131" 10005 1991  2        0  .0719    .12909799999999952
  81. "131" 10005 1991  3        0  .0265    .07389300000000028
  82. "131" 10005 1991  4        0 -.0028    .02665700000000002
  83. "131" 10005 1991  5        0  .0365   .026667999999999897
  84. "131" 10005 1991  6       .6 -.0494   -.03597300000000006
  85. "131" 10005 1991  7        .  .0424   .029280000000000077
  86. "374" 10006 1960  1  .005155 -.0698  -.042502000000000005
  87. "374" 10006 1960  2  .046154  .0117               .005578
  88. "374" 10006 1960  3 -.059553 -.0163  -.028376000000000002
  89. "374" 10006 1960  4 -.081794 -.0171               -.02163
  90. "374" 10006 1960  5  .048851  .0312   .022846000000000005
  91. "374" 10006 1960  6  .027778  .0208   .019208999999999997
  92. "374" 10006 1960  7 -.013514 -.0237              -.020898
  93. "374" 10006 1960  8 -.021918  .0301               .036248
  94. "374" 10006 1960  9 -.142045 -.0599  -.061124000000000005
  95. "374" 10006 1960 10 -.013245 -.0071               -.02543
  96. "374" 10006 1960 11  .003356  .0469    .04519399999999999
  97. "374" 10006 1960 12  .034014  .0471               .035895
  98. "374" 10006 1961  1  .322368   .062               .080148
  99. "374" 10006 1961  2  .014925  .0357   .058730000000000004
  100. "374" 10006 1961  3  .086849  .0289    .04788799999999999
  101. "374" 10006 1961  4  .022831  .0029  .0077870000000000005
  102. "374" 10006 1961  5  .078125   .024   .039771999999999995
  103. end
复制代码

gpt生成了示例代码,但是好像不行,仅作参考。
  1. gen date1 = ym(year, month)
  2. format date1 %tm
  3. sort permno date1

  4. gen expected_return = .
  5. gen idiosyncratic_return = .
  6. gen window_length = .

  7. * 定义窗口
  8. local min_window = 24
  9. local max_window = 60
  10. bysort permno: gen id = _n  // 为了便于引用行数
  11. foreach permno in permno {
  12.     local num_obs = _N

  13.     forvalues i = `max_window' / `num_obs' {
  14.         if `i' > `max_window' continue

  15.         local start = max(`i' - `max_window' + 1, 1)
  16.         local end = `i'

  17.         // 检查窗口长度是否满足最小要求
  18.         if `end' - `start' + 1 >= `min_window' {
  19.             // 进行回归
  20.             quietly reg ret r__rf rm_rf [in `start'/`end']
  21.             
  22.             // 提取系数
  23.             local alpha = _b[_cons]
  24.             local betaM = _b[rm_rf]
  25.             local betaIND = _b[r__rf]

  26.             // 预测未来的回报
  27.             local future_date = date1[`end'] + 12

  28.             // 确保未来数据存在
  29.             if !missing(rm_rf[`future_date']) {
  30.                 local expected_return = `alpha' + `betaM' * rm_rf[`future_date'] + `betaIND' * r__rf[`future_date']
  31.                
  32.                 // 计算特质回报
  33.                 local idiosyncratic_return = r__rf[`future_date'] - `expected_return'
  34.                
  35.                 // 存储结果
  36.                 replace expected_return = `expected_return' in `future_date'
  37.                 replace idiosyncratic_return = `idiosyncratic_return' in `future_date'
  38.                 replace window_length = `end' - `start' + 1 in `future_date'
  39.             }
  40.         }
  41.     }
  42. }
复制代码


二维码

扫码加我 拉你入群

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

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

关键词:滚动回归 historical Estimation regression estimated

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-8 14:05