Hi,

I am trying to do Survival (Duration) Analysis with multiple records per subject.


Particularly, I have product ID, date of price observation, the price change(in percentage). My event is the price change. So, if I have price change(in percentage), event=1, if price is unchanged, event=0.

I need to add duration variable. I mean, if the price of a product does not change for several months, I need the count of that months. In my dataset I have 450 products and 9 years. Here is an example from my dataset. The variable "Duration" is created manually be myself.

Please help me with the code to create that variable(duaration) for the whole dataset.


PS. if the code does not work please copy from the attached file. For me it does not work when I copy from web.

-----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int id float change byte duration float month byte event
153   .0297 1 718 1
153   .0785 7 719 1
154       0 6 612 0
154       0 5 613 0
154       0 4 614 0
154       0 3 615 0
154       0 2 616 0
154       0 1 617 0
154  .60469 1 618 1
154 1.09125 2 619 1
154       0 1 620 0
154    -.02 1 621 1
end
format %tm month
------------------