楼主: 卢冲
1414 4

[面板数据求助] stata面板数据处理 [推广有奖]

  • 3关注
  • 1粉丝

已卖:336份资源

院士

74%

还不是VIP/贵宾

-

威望
0
论坛币
12141 个
通用积分
24.2898
学术水平
0 点
热心指数
3 点
信用等级
0 点
经验
34520 点
帖子
2308
精华
0
在线时间
1497 小时
注册时间
2011-7-6
最后登录
2025-12-29

楼主
卢冲 学生认证  发表于 2020-12-16 22:07:54 |AI写论文
20论坛币
----------------------- copy starting from the next line -----------------------
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input float(IDD age migrate city year duration)
  4. 1 1985 0    .    .  1
  5. 1 1986 0    .    .  2
  6. 1 1987 0    .    .  3
  7. 1 1988 0    .    .  4
  8. 1 1989 0    .    .  5
  9. 1 1990 1 5331 1990  6
  10. 1 1991 0    .    .  7
  11. 1 1992 0    .    .  8
  12. 1 1993 0    .    .  9
  13. 2 1984 0    .    .  1
  14. 2 1985 0    .    .  2
  15. 2 1986 0    .    .  3
  16. 2 1987 0    .    .  4
  17. 2 1988 0    .    .  5
  18. 2 1989 0    .    .  6
  19. 2 1990 1 5331 1990  7
  20. 2 1991 0    .    .  8
  21. 2 1992 0    .    .  9
  22. 2 1993 1 1101 1993 10
  23. 2 1994 0    .    . 11
  24. 2 1995 0    .    . 12
  25. 2 1996 0    .    . 13
  26. end
复制代码

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

Listed 22 out of 22 observations


如何使用什么代码使得对于ID=1,在1991-1993年duration的赋值分别从1-3。
同理,对于ID=2,在1991-1993年duration的赋值分别为1,2,3。
1994-1996赋值为1,2,3。
得到如下结果:
copy starting from the next line        ------        ----------------
  1. * Example generated by -dataex-. To install: ssc install        dataex
  2. clear
  3. input float(IDD age migrate city year duration)
  4. 1 1985 0    .    . 1
  5. 1 1986 0    .    . 2
  6. 1 1987 0    .    . 3
  7. 1 1988 0    .    . 4
  8. 1 1989 0    .    . 5
  9. 1 1990 1 5331 1990 6
  10. 1 1991 0    .    . 1
  11. 1 1992 0    .    . 2
  12. 1 1993 0    .    . 3
  13. 2 1984 0    .    . 1
  14. 2 1985 0    .    . 2
  15. 2 1986 0    .    . 3
  16. 2 1987 0    .    . 4
  17. 2 1988 0    .    . 5
  18. 2 1989 0    .    . 6
  19. 2 1990 1 5331 1990 7
  20. 2 1991 0    .    . 1
  21. 2 1992 0    .    . 2
  22. 2 1993 1 1101 1993 3
  23. 2 1994 0    .    . 1
  24. 2 1995 0    .    . 2
  25. 2 1996 0    .    . 3
  26. end
复制代码

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

Listed 22 out of 22 observations

.
end of do-file


最佳答案

黃河泉 查看完整内容

請 ssc install tsspell 並試試
关键词:stata面板数据 STATA面板 面板数据处理 Stata 面板数据

沙发
黃河泉 在职认证  发表于 2020-12-16 22:07:55
請 ssc install tsspell 並試試
  1. xtset IDD age
  2. tsspell migrate
  3. replace _seq = _seq[_n-1]+1 if migrate == 1
复制代码

藤椅
zdlspace 学生认证  发表于 2020-12-17 01:52:23
replace duration=1 if age==1991
replace duration=2 if age==1992
replace duration=3 if age==1993
replace duration=1 if age==1994
replace duration=2 if age==1995

Raymond
Stata 17.0, MP(4)

板凳
卢冲 学生认证  发表于 2020-12-17 09:26:05
黃河泉 发表于 2020-12-16 22:07
請 ssc install tsspell 並試試
感谢黄老师,有效。

报纸
黃河泉 在职认证  发表于 2020-12-17 10:30:17
卢冲 发表于 2020-12-17 09:26
感谢黄老师,有效。
Great to hear that.

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

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