我新学stata有很多地方不了解 希望各位大侠帮忙解答一下 先感谢一下
id date newcycle cyclenum
311 1997-06-01 1 1
311 1997-06-22 0 1
311 1997-07-14 0 1
311 1998-09-17 1 2
311 1998-10-08 0 2
311 1998-12-07 2 3
311 1999-02-07 0 3
432 1997-11-04 2 1
数据是上面这个样子
newcycle是指病人开始新的循环 每个循环开始用1或者2表示不固定用哪个 如果是0就还停留在上一个循环中
我想创建出cyclenum这个变量
这个变量是指明这个病人现在处于哪个循环中 比newcycle更清晰明了
这个变量该怎么创建?
老师给了我一些hints 但是我还是不太理解
Hint 1: sort the data on id, and within id, the date
Hint 2: make a new, temporary, variable that stores a 1 if the observation is a newcycle and 0 if not.
Use the correct function AND you operate within each stratum as defined by the id
到底该用哪个函数啊?