请选择 进入手机版 | 继续访问电脑版
12919 14

[面板数据求助] [求助]面板数据求t-1期、t+1期 [推广有奖]

黃河泉 在职认证  发表于 2018-10-18 15:49:44 |显示全部楼层 |坛友微信交流群
第三类纽约人 发表于 2018-10-18 13:19
谢谢~我试了labe drop _all ,然后数据全部变了,我做滞后还是不行诶
变成了这样:
clear
请将下列两线之间的东西全部发出来:

----------------------- copy starting from the next line -----------------------

------------------ copy up to and including the previous line ------------------
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input int(price mpg)
  4. 4099 22
  5. 4749 17
  6. 3799 22
  7. 4816 20
  8. 7827 15
  9. 5788 18
  10. 4453 26
  11. 5189 20
  12. 10372 16
  13. 4082 19
  14. 11385 14
  15. 14500 14
  16. 15906 21
  17. 3299 29
  18. 5705 16
  19. 4504 22
  20. 5104 22
  21. 3667 24
  22. 3955 19
  23. 3984 30
  24. end
复制代码

使用道具

317792209 在职认证  学生认证  发表于 2018-10-19 09:45:16 |显示全部楼层 |坛友微信交流群
你这个是不能用encode的,我试了你的数据,结果你的数据encode以后全都变了,stata默认将其转换成了按顺序排列的分类数据。如果你的数据导入是红色的,你可以用这个命令:
gen 新变量=real(旧变量)
然后
sort stkcd date
by stkcd:gen wkretmv1= wkretmv[_n-1]
by stkcd:gen wkretmv2= wkretmv[_n+1]
如图:
QQ图片20181019100123.png


使用道具

317792209 发表于 2018-10-19 09:45
你这个是不能用encode的,我试了你的数据,结果你的数据encode以后全都变了,stata默认将其转换成了按顺序排 ...
您好,我用了你的方法,用gen 新变量=real(旧变量)成功生成股票代码stkcd那列了,不过日期这列不知道怎么回事不能生成,请您看一下,谢谢!
gen 新变量=real(旧变量)
----------------------- copy starting from the next line -----------------------
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input float stkcd str10 date1 float(wkret wkretmv wkrethv data)
  4. 2 "2006-01-06"  .0882  .0452  .0665 .
  5. 2 "2006-01-13" -.0512  .0209 -.0031 .
  6. 2 "2006-01-20"  .0225  .0187  .0398 .
  7. 2 "2006-01-25"  .0835   .012  .0456 .
  8. 2 "2006-02-10"  .0467  .0272  .0178 .
  9. 2 "2006-02-17"  .0853 -.0237  .0372 .
  10. 2 "2006-02-24"  .0018   .025  .0265 .
  11. 2 "2006-03-03" -.0285 -.0177 -.0252 .
  12. 2 "2006-03-10" -.0752 -.0486 -.0556 .
  13. 2 "2006-03-17"  .0833  .0139  .0544 .
  14. 2 "2006-03-24"  .0861  .0289  .0642 .
  15. 2 "2006-03-31"  .1046  .0177  .0764 .
  16. 2 "2006-04-07"  .0427   .058  .0522 .
  17. 2 "2006-04-14" -.0337  .0174 -.0222 .
  18. 2 "2006-04-21"  .0106  .0057 -.0066 .
  19. 2 "2006-04-28"  -.066  .0145 -.0395 .
  20. 2 "2006-05-12"  -.008  .1218  .0245 .
  21. 2 "2006-05-19" -.0178  .0669  .0183 .
  22. 2 "2006-05-26" -.0214 -.0154  .0054 .
  23. 2 "2006-06-02" -.0505  .0615 -.0058 .
  24. 2 "2006-06-09" -.0621 -.0815 -.0876 .
  25. 2 "2006-06-16"  .0529  .0239  .0282 .
  26. 2 "2006-06-23" -.0251  .0261 -.0098 .
  27. 2 "2006-06-30"  .0405  .0431  .0351 .
  28. 2 "2006-07-07" -.0088  .0267  .0191 .
  29. 2 "2006-07-14"  .1071 -.0425  .0596 .
  30. 2 "2006-07-21" -.0016  .0069  .0202 .
  31. 2 "2006-07-28" -.0397 -.0189 -.0134 .
  32. 2 "2006-08-03" -.0207 -.0968      . .
  33. 2 "2006-08-11"  .0317  .0302  .0363 .
  34. 2 "2006-08-18"  .0666 -.0069  .0294 .
  35. 2 "2006-08-25"   .024  .0228  .0104 .
  36. 2 "2006-09-01"  .0578   .027  .0627 .
  37. 2 "2006-09-08"  .0015  .0063 -.0011 .
  38. 2 "2006-09-15"  .0693  .0116  .0225 .
  39. 2 "2006-09-22"  .0552  .0154  .0443 .
  40. 2 "2006-09-29" -.0105  .0211  -.003 .
  41. 2 "2006-10-13" -.0555  .0153 -.0413 .
  42. 2 "2006-10-20"  .1035  .0088  .0315 .
  43. 2 "2006-10-27"  .0393 -.0188  .0207 .
  44. 2 "2006-11-03"  .0049  .0188    .01 .
  45. 2 "2006-11-10"  .1117 -.0149  .0421 .
  46. 2 "2006-11-17"  .1463  .0196  .0896 .
  47. 2 "2006-11-24"  .0286  .0411   .068 .
  48. 2 "2006-12-01"  .1204  .0704  .0861 .
  49. 2 "2006-12-08" -.0388 -.0233 -.0416 .
  50. 2 "2006-12-15"  .1393  .0817  .1143 .
  51. 2 "2006-12-20"  .0966  .0213      . .
  52. 2 "2006-12-29"  .0626  .0261  .0422 .
  53. 4 "2006-01-06"  .1449  .0452  .0607 .
  54. end
复制代码
------------------ copy up to and including the previous line ------------------

使用道具

317792209 在职认证  学生认证  发表于 2018-10-19 19:20:35 |显示全部楼层 |坛友微信交流群
第三类纽约人 发表于 2018-10-19 16:56
您好,我用了你的方法,用gen 新变量=real(旧变量)成功生成股票代码stkcd那列了,不过日期这列不知道怎么 ...
因为中间有——啊,执行命令destring date, replace ignore("-")

使用道具

317792209 在职认证  学生认证  发表于 2018-10-19 19:47:04 |显示全部楼层 |坛友微信交流群
. dataex in 1/5

----------------------- copy starting from the next line -----------------------
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input long date
  4. 20060106
  5. 20060107
  6. 20060108
  7. 20060109
  8. 20060110
  9. end
复制代码

------------------ copy up to and including the previous line ------------------

使用道具

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

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

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

GMT+8, 2024-3-28 18:05