样本数据:
clear
* Input data
input student CITATION EXPELLED hadCITATION hadEXPELLED
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
2 0 0 0 0
2 0 0 0 0
2 1 0 1 0
2 1 0 1 0
2 0 0 1 0
3 1 0 1 0
3 0 1 1 1
3 1 1 1 1
3 1 0 1 1
3 1 0 1 1
4 . . . .
4 . 0 . 0
4 0 0 0 0
4 0 1 0 1
4 1 0 1 0
我想创建这些hadCITATION和hadEXPELLED变量列,这些列根据CITATION和EXPELLED的响应进行更新。
答案 0 :(得分:1)
这可能会有所帮助。我看不到没有时间或序列变量就没有道理。我的猜测是,一旦您获得了CITATION或EXPULSION,那便是您的历史了。规则可能更复杂,但是我看不到您在解释它们。 我看不到您为学生4做例子的理由。
clear
input student CITATION EXPELLED hadCITATION hadEXPELLED
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
2 0 0 0 0
2 0 0 0 0
2 1 0 1 0
2 1 0 1 0
2 0 0 1 0
3 1 0 1 0
3 0 1 1 1
3 1 1 1 1
3 1 0 1 1
3 1 0 1 1
4 . . . .
4 . 0 . 0
4 0 0 0 0
4 0 1 0 1
4 1 0 1 0
end
gen long time = _n
bysort student (time) : gen want1 = sum(CITATION) > 0
by student: gen want2 = sum(EXPELLED) > 0
list student CIT EXP hadCIT hadEXP want?, sepby(student)
+---------------------------------------------------------------------+
| student CITATION EXPELLED hadCIT~N hadEXP~D want1 want2 |
|---------------------------------------------------------------------|
1. | 1 0 0 0 0 0 0 |
2. | 1 0 0 0 0 0 0 |
3. | 1 0 0 0 0 0 0 |
4. | 1 0 0 0 0 0 0 |
5. | 1 0 0 0 0 0 0 |
|---------------------------------------------------------------------|
6. | 2 0 0 0 0 0 0 |
7. | 2 0 0 0 0 0 0 |
8. | 2 1 0 1 0 1 0 |
9. | 2 1 0 1 0 1 0 |
10. | 2 0 0 1 0 1 0 |
|---------------------------------------------------------------------|
11. | 3 1 0 1 0 1 0 |
12. | 3 0 1 1 1 1 1 |
13. | 3 1 1 1 1 1 1 |
14. | 3 1 0 1 1 1 1 |
15. | 3 1 0 1 1 1 1 |
|---------------------------------------------------------------------|
16. | 4 . . . . 0 0 |
17. | 4 . 0 . 0 0 0 |
18. | 4 0 0 0 0 0 0 |
19. | 4 0 1 0 1 0 1 |
20. | 4 1 0 1 0 1 1 |
+---------------------------------------------------------------------+