运算逻辑:
若2018年crise为1,则2018年crisedown为1;
若2017年crise为1,或2018年cirsedown为1且2017年down为1,则2017年crisedown为1。
若2016年crise为1,或2017年cirsedown为1且2016年down为1,则2016年crisedown为1。
以此依次类推直到2001年。
样本数据如下:注意crisedown为结果并非开始就有的数据* Example generated by -dataex-. To install: ssc install dataex
clear
input int year float(down crise) double crisedown
2001 0 0 0
2002 1 1 1
2003 0 0 0
2004 0 0 0
2005 0 0 0
2006 0 0 0
2007 1 0 0
2008 0 0 0
2009 1 0 0
2010 0 0 0
2011 1 0 0
2012 0 0 0
2013 1 0 0
2014 0 0 0
2015 1 0 1
2016 1 1 1
2017 0 1 1
2018 0 0 0
end
这位坛友用循环折腾了半天还报错了,其实没必要用循环,两行命令即可搞定。
- clear
- input int year float(down crise)
- 2001 0 0
- 2002 1 1
- 2003 0 0
- 2004 0 0
- 2005 0 0
- 2006 0 0
- 2007 1 0
- 2008 0 0
- 2009 1 0
- 2010 0 0
- 2011 1 0
- 2012 0 0
- 2013 1 0
- 2014 0 0
- 2015 1 0
- 2016 1 1
- 2017 0 1
- 2018 0 0
- end
- tsset year
- gen crisedown=(crise==1)
- replace crisedown=1 if F.crisedown==1 & down==1
- list
- +-----------------------------------------+
- | year down crise crised~n wanted |
- |-----------------------------------------|
- 1. | 2001 0 0 0 0 |
- 2. | 2002 1 1 1 1 |
- 3. | 2003 0 0 0 0 |
- 4. | 2004 0 0 0 0 |
- 5. | 2005 0 0 0 0 |
- |-----------------------------------------|
- 6. | 2006 0 0 0 0 |
- 7. | 2007 1 0 0 0 |
- 8. | 2008 0 0 0 0 |
- 9. | 2009 1 0 0 0 |
- 10. | 2010 0 0 0 0 |
- |-----------------------------------------|
- 11. | 2011 1 0 0 0 |
- 12. | 2012 0 0 0 0 |
- 13. | 2013 1 0 0 0 |
- 14. | 2014 0 0 0 0 |
- 15. | 2015 1 0 1 1 |
- |-----------------------------------------|
- 16. | 2016 1 1 1 1 |
- 17. | 2017 0 1 1 1 |
- 18. | 2018 0 0 0 0 |
- +-----------------------------------------+


雷达卡




京公网安备 11010802022788号







