Dear All, I was asked this question. The data is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str15 agency str12 issuer int ymd byte order float relate
"A" "x" 20020 1 0
"A" "x" 20020 1 0
"A" "x" 20020 1 0
"A" "y" 20444 1 0
"A" "y" 20444 1 0
"A" "y" 20786 2 0
"A" "y" 20786 2 0
"A" "y" 20786 2 0
"A" "y" 20803 3 0
"A" "y" 20803 3 0
"A" "z" 21109 1 0
"A" "z" 21109 1 0
"A" "z" 21179 2 0
"A" "z" 21179 2 0
end
format %tdnn/dd/CCYY ymd
  1. For each pair of agency and issuer, I'd like to to do the following calculation.
  2. If order = 1, then `relate' = 0.
  3. If order = 2, then `relate' is obtained by subtracting ymd when order =1 from ymd when order =2. Similarly, for order =3, the `relate' variable is again obtained by subtracting ymd when order =2 from ymd when order =3, and so on.