Dear All, I found this question here https://bbs.pinggu.org/thread-7813996-1-1.html。The data set is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long stkcd str10 trddy double risk
2 "1997-01-13" 0
2 "1997-01-14" 0
2 "1997-01-15" 0
2 "1997-01-16" 0
2 "1997-01-17" 0
2 "1997-01-20" 0
2 "1997-01-21" 0
2 "1997-01-22" 0
2 "1997-01-23" 0
2 "1997-01-24" 0
2 "1997-01-27" 0
2 "1997-01-28" 0
2 "1997-01-29" 0
2 "1997-01-30" 0
2 "1997-01-31" 0
2 "1997-02-17" 0
2 "1997-02-18" 0
2 "1997-02-19" 0
2 "1997-02-20" 0
2 "1997-02-21" 0
2 "1997-02-24" 0
2 "1997-02-25" 0
2 "1997-02-26" 0
2 "1997-02-27" 0
2 "1997-02-28" 0
2 "1997-03-03" 0
2 "1997-03-04" 0
2 "1997-03-05" 0
2 "1997-03-06" 0
2 "1997-03-07" 1
2 "1997-03-10" 0
2 "1997-03-12" 0
2 "1997-03-13" 0
2 "1997-03-14" 0
2 "1997-03-17" 0
2 "1997-03-18" 0
2 "1997-03-19" 0
2 "1997-03-20" 0
2 "1997-03-21" 0
2 "1997-03-24" 1
2 "1997-03-25" 1
2 "1997-03-26" 1
2 "1997-03-27" 1
2 "1997-03-28" 1
2 "1997-03-31" 1
2 "1997-04-01" 1
2 "1997-04-02" 1
2 "1997-04-03" 1
2 "1997-04-04" 1
2 "1997-04-07" 1
2 "1997-04-08" 1
2 "1997-04-09" 1
2 "1997-04-10" 1
2 "1997-04-11" 1
2 "1997-04-14" 1
2 "1997-04-15" 1
2 "1997-04-16" 1
2 "1997-04-17" 1
2 "1997-04-18" 1
2 "1997-04-21" 1
2 "1997-04-22" 1
2 "1997-04-23" 1
2 "1997-04-24" 1
2 "1997-04-25" 1
2 "1997-04-28" 1
2 "1997-04-29" 1
2 "1997-04-30" 1
2 "1997-05-05" 1
2 "1997-05-06" 1
2 "1997-05-07" 1
2 "1997-05-08" 1
2 "1997-05-09" 1
2 "1997-05-12" 1
2 "1997-05-13" 1
2 "1997-05-14" 1
2 "1997-05-15" 1
2 "1997-05-16" 1
2 "1997-05-19" 0
2 "1997-05-20" 0
2 "1997-05-21" 0
2 "1997-05-22" 0
2 "1997-05-23" 0
2 "1997-05-26" 0
2 "1997-05-27" 0
2 "1997-05-28" 0
2 "1997-05-29" 0
2 "1997-06-02" 0
2 "1997-06-03" 0
2 "1997-06-04" 0
2 "1997-06-05" 0
2 "1997-06-06" 0
2 "1997-06-09" 0
2 "1997-06-10" 0
2 "1997-06-11" 0
2 "1997-06-12" 0
2 "1997-06-13" 0
2 "1997-06-16" 0
2 "1997-06-17" 0
2 "1997-06-18" 0
2 "1997-06-19" 0

3 "1997-01-13" 0
3 "1997-01-14" 0
3 "1997-01-15" 0
3 "1997-01-16" 0
3 "1997-01-17" 0
3 "1997-01-20" 0
3 "1997-01-21" 0
3 "1997-01-22" 0
3 "1997-01-23" 0
3 "1997-01-24" 0
3 "1997-01-27" 0
3 "1997-01-28" 0
3 "1997-01-29" 0
3 "1997-01-30" 0
3 "1997-01-31" 0
3 "1997-02-17" 0
3 "1997-02-18" 0
3 "1997-02-19" 0
3 "1997-02-20" 0
3 "1997-02-21" 0
3 "1997-02-24" 0
3 "1997-02-25" 0
3 "1997-02-26" 0
3 "1997-02-27" 0
3 "1997-02-28" 0
3 "1997-03-03" 0
3 "1997-03-04" 0
3 "1997-03-05" 0
3 "1997-03-06" 0
3 "1997-03-07" 0
3 "1997-03-10" 0
3 "1997-03-11" 0
3 "1997-03-12" 1
3 "1997-03-13" 1
3 "1997-03-14" 1
3 "1997-03-17" 1
3 "1997-03-18" 1
3 "1997-03-19" 1
3 "1997-03-20" 1
3 "1997-03-21" 1
3 "1997-03-24" 1
3 "1997-03-25" 1
3 "1997-03-26" 1
3 "1997-03-27" 1
3 "1997-03-28" 1
3 "1997-03-31" 1
3 "1997-04-01" 1
3 "1997-04-02" 1
3 "1997-04-03" 1
3 "1997-04-04" 1
3 "1997-04-07" 1
3 "1997-04-08" 1
3 "1997-04-09" 1
3 "1997-04-10" 1
3 "1997-04-11" 1
3 "1997-04-14" 1
3 "1997-04-15" 1
3 "1997-04-16" 1
3 "1997-04-17" 1
3 "1997-04-18" 1
3 "1997-04-21" 1
3 "1997-04-22" 1
3 "1997-04-23" 1
3 "1997-04-24" 1
3 "1997-04-25" 0
3 "1997-04-28" 0
3 "1997-04-29" 0
3 "1997-04-30" 0
3 "1997-05-05" 0
3 "1997-05-06" 0
3 "1997-05-07" 0
3 "1997-05-08" 0
3 "1997-05-09" 0
3 "1997-05-12" 0
3 "1997-05-13" 0
3 "1997-05-14" 0
3 "1997-05-15" 0
3 "1997-05-16" 0
3 "1997-05-19" 0
3 "1997-05-20" 0
3 "1997-05-21" 0
3 "1997-05-22" 0
3 "1997-05-23" 0
3 "1997-05-26" 0
3 "1997-05-27" 0
3 "1997-05-28" 0
3 "1997-05-29" 0
3 "1997-05-30" 0
3 "1997-06-02" 0
3 "1997-06-03" 0
3 "1997-06-04" 0
3 "1997-06-05" 0
3 "1997-06-06" 0
3 "1997-06-09" 0
3 "1997-06-10" 0
3 "1997-06-11" 0
3 "1997-06-12" 0
3 "1997-06-13" 0
3 "1997-06-16" 0
3 "1997-06-17" 0
end
The `trddy' denotes consecutive trading days. I'd like to have a dummy which is equal to 1 if there are 15 consecutive days with risk = 1 (including the current trading day). I did this by
Code:
bys stkcd (trddy): gen t = _n
tsset stkcd t

// ssc install tsspell
tsspell risk

gen x = risk*_seq
gen wanted = 0
replace wanted = 1 if x >= 15
I wonder if there are other suggestions? Thanks.