The first "period" of the series will be NAs, e.g., (NA, NA, NA, 1, 2, 3, 1, 2, 3, ...), because @day(-1) is NA for the first observation. That causes @day<>@day(-1) to evaluate to NA instead of true. NA is interpreted as false, therefore @recode assigns tx(-1) + 1, which is also NA, to the first observation of tx. For the rest of the first period @day<>@day(-1) is false, so @recode continues to assign tx(-1) + 1 to subsequent observations of tx, which just propagates the NA. Only when you hit the second period is @day<>@day(-1) true, and things work correctly from that point onward. The problem is the first evaluation of @day(-1) that evaluates to NA, but you can easily change your @recode condition in many ways to handle that special case. For example,
Code: Select all
series tx = @recode(@day<>@day(-1) or @isna(@day(-1)), 1, tx(-1) + 1)