Dear All, Suppose that I have this data set
There are three individuals, id=1,2,3. Each has an insurance contract for `all' years. In the `event' year, they have accidents. I expand the data by
and obtain
However, I wish to have a final data set like
Given this expanded (unbalanced) panel data, I'd like to have the `wanted' to be 1 if there is an accident in the `t' year. Any suggestions? Thanks.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(id event all) 1 1 4 2 3 5 3 2 6 3 4 6 end
Code:
expand po_prem_year+1 sort policy_no event_po_year by policy_no: gen t = _n-1
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(policy_no event_po_year po_prem_year) float t 1 1 4 0 1 1 4 1 1 1 4 2 1 1 4 3 1 1 4 4 2 3 5 0 2 3 5 1 2 3 5 2 2 3 5 3 2 3 5 4 2 3 5 5 3 2 6 0 3 2 6 1 3 2 6 2 3 2 6 3 3 2 6 4 3 2 6 5 3 2 6 6 3 4 6 7 3 4 6 8 3 4 6 9 3 4 6 10 3 4 6 11 3 4 6 12 3 4 6 13 end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(id wanted all) float t 1 0 4 0 1 1 4 1 1 0 4 2 1 0 4 3 1 0 4 4 2 0 5 0 2 0 5 1 2 0 5 2 2 1 5 3 2 0 5 4 2 0 5 5 3 0 6 0 3 0 6 1 3 1 6 2 3 0 6 3 3 1 6 4 3 0 6 5 3 0 6 6 end

Comment