Dear Stata Community!
I need your help! I am working with very big data files (~20Gb) containing around 1 million observations and 15 to 20 000 variables. I'm trying to reduce the size of the data file to around 100 variables max. However, when I loop through my data and try to subsequently reduce the size, Stata takes way too long to perform the tasks. Maybe some of you have an idea of how to speed up the code and get to the same outcome! All help is much appreciated
Here is the code I'm currently running...
// US 10Y 5BP SHORT
clear all
quietly {
use TF_Short_10Y_5BP_US_end.dta
gen Treasury_coupon_1 = Treasury
gen Treasury_coupon_2 = Treasury
gen Treasury_coupon_3 = Treasury
gen Treasury_coupon_4 = Treasury
gen Treasury_coupon_5 = Treasury
gen Treasury_coupon_6 = Treasury
gen Treasury_coupon_7 = Treasury
gen Treasury_coupon_8 = Treasury
gen Treasury_coupon_9 = Treasury
gen Treasury_coupon_10 = Treasury
gen Treasury_coupon_11 = Treasury
gen Treasury_coupon_12 = Treasury
gen Treasury_coupon_13 = Treasury
gen Treasury_coupon_14 = Treasury
gen Treasury_coupon_15 = Treasury
gen Treasury_coupon_16 = Treasury
gen Treasury_coupon_17 = Treasury
gen Treasury_coupon_18 = Treasury
gen Treasury_coupon_19 = Treasury
gen Treasury_coupon_20 = Treasury + 100
gen Swap_coupon_1 = Swap
gen Swap_coupon_2 = Swap
gen Swap_coupon_3 = Swap
gen Swap_coupon_4 = Swap
gen Swap_coupon_5 = Swap
gen Swap_coupon_6 = Swap
gen Swap_coupon_7 = Swap
gen Swap_coupon_8 = Swap
gen Swap_coupon_9 = Swap
gen Swap_coupon_10 = Swap
gen Swap_coupon_11 = Swap
gen Swap_coupon_12 = Swap
gen Swap_coupon_13 = Swap
gen Swap_coupon_14 = Swap
gen Swap_coupon_15 = Swap
gen Swap_coupon_16 = Swap
gen Swap_coupon_17 = Swap
gen Swap_coupon_18 = Swap
gen Swap_coupon_19 = Swap
gen Swap_coupon_20 = Swap + 100
gen LIBOR_coupon = LIBOR + 100
gen Treasury_disc_1 = 1
gen Treasury_disc_2 = 1
gen Treasury_disc_3 = 1
gen Treasury_disc_4 = 1
gen Treasury_disc_5 = 1
gen Treasury_disc_6 = 1
gen Treasury_disc_7 = 1
gen Treasury_disc_8 = 1
gen Treasury_disc_9 = 1
gen Treasury_disc_10 = 1
gen Treasury_disc_11 = 1
gen Treasury_disc_12 = 1
gen Treasury_disc_13 = 1
gen Treasury_disc_14 = 1
gen Treasury_disc_15 = 1
gen Treasury_disc_16 = 1
gen Treasury_disc_17 = 1
gen Treasury_disc_18 = 1
gen Treasury_disc_19 = 1
gen Treasury_disc_20 = 1
gen Swap_disc_1 = 1
gen Swap_disc_2 = 1
gen Swap_disc_3 = 1
gen Swap_disc_4 = 1
gen Swap_disc_5 = 1
gen Swap_disc_6 = 1
gen Swap_disc_7 = 1
gen Swap_disc_8 = 1
gen Swap_disc_9 = 1
gen Swap_disc_10 = 1
gen Swap_disc_11 = 1
gen Swap_disc_12 = 1
gen Swap_disc_13 = 1
gen Swap_disc_14 = 1
gen Swap_disc_15 = 1
gen Swap_disc_16 = 1
gen Swap_disc_17 = 1
gen Swap_disc_18 = 1
gen Swap_disc_19 = 1
gen Swap_disc_20 = 1
gen Treasury_coupon_1_date =.
gen Treasury_coupon_2_date =.
gen Treasury_coupon_3_date =.
gen Treasury_coupon_4_date =.
gen Treasury_coupon_5_date =.
gen Treasury_coupon_6_date =.
gen Treasury_coupon_7_date =.
gen Treasury_coupon_8_date =.
gen Treasury_coupon_9_date =.
gen Treasury_coupon_10_date =.
gen Treasury_coupon_11_date =.
gen Treasury_coupon_12_date =.
gen Treasury_coupon_13_date =.
gen Treasury_coupon_14_date =.
gen Treasury_coupon_15_date =.
gen Treasury_coupon_16_date =.
gen Treasury_coupon_17_date =.
gen Treasury_coupon_18_date =.
gen Treasury_coupon_19_date =.
gen Treasury_coupon_20_date =.
gen Swap_coupon_1_date =.
gen Swap_coupon_2_date =.
gen Swap_coupon_3_date =.
gen Swap_coupon_4_date =.
gen Swap_coupon_5_date =.
gen Swap_coupon_6_date =.
gen Swap_coupon_7_date =.
gen Swap_coupon_8_date =.
gen Swap_coupon_9_date =.
gen Swap_coupon_10_date =.
gen Swap_coupon_11_date =.
gen Swap_coupon_12_date =.
gen Swap_coupon_13_date =.
gen Swap_coupon_14_date =.
gen Swap_coupon_15_date =.
gen Swap_coupon_16_date =.
gen Swap_coupon_17_date =.
gen Swap_coupon_18_date =.
gen Swap_coupon_19_date =.
gen Swap_coupon_20_date =.
gen LIBOR_coupon_date=.
gen REPO_reset_date =.
quietly {
forvalues i = 1/2119 {
egen trade_start_date = min(Date) if Tradenumb == `i'
egen trade_end_date = max(Date) if Tradenumb == `i'
replace Treasury_coupon_1_date = trade_start_date + 180 if Tradenumb == `i'
replace Treasury_coupon_2_date = trade_start_date + 360 if Tradenumb == `i'
replace Treasury_coupon_3_date = trade_start_date + 540 if Tradenumb == `i'
replace Treasury_coupon_4_date = trade_start_date + 720 if Tradenumb == `i'
replace Treasury_coupon_5_date = trade_start_date + 900 if Tradenumb == `i'
replace Treasury_coupon_6_date = trade_start_date + 1080 if Tradenumb == `i'
replace Treasury_coupon_7_date = trade_start_date + 1260 if Tradenumb == `i'
replace Treasury_coupon_8_date = trade_start_date + 1440 if Tradenumb == `i'
replace Treasury_coupon_9_date = trade_start_date + 1620 if Tradenumb == `i'
replace Treasury_coupon_10_date = trade_start_date + 1800 if Tradenumb == `i'
replace Treasury_coupon_11_date = trade_start_date + 1960 if Tradenumb == `i'
replace Treasury_coupon_12_date = trade_start_date + 2160 if Tradenumb == `i'
replace Treasury_coupon_13_date = trade_start_date + 2340 if Tradenumb == `i'
replace Treasury_coupon_14_date = trade_start_date + 2520 if Tradenumb == `i'
replace Treasury_coupon_15_date = trade_start_date + 2700 if Tradenumb == `i'
replace Treasury_coupon_16_date = trade_start_date + 2880 if Tradenumb == `i'
replace Treasury_coupon_17_date = trade_start_date + 3060 if Tradenumb == `i'
replace Treasury_coupon_18_date = trade_start_date + 3240 if Tradenumb == `i'
replace Treasury_coupon_19_date = trade_start_date + 3420 if Tradenumb == `i'
replace Treasury_coupon_20_date = trade_start_date + 3600 if Tradenumb == `i'
replace Swap_coupon_1_date = trade_start_date + 180 if Tradenumb == `i'
replace Swap_coupon_2_date = trade_start_date + 360 if Tradenumb == `i'
replace Swap_coupon_3_date = trade_start_date + 540 if Tradenumb == `i'
replace Swap_coupon_4_date = trade_start_date + 720 if Tradenumb == `i'
replace Swap_coupon_5_date = trade_start_date + 900 if Tradenumb == `i'
replace Swap_coupon_6_date = trade_start_date + 1080 if Tradenumb == `i'
replace Swap_coupon_7_date = trade_start_date + 1260 if Tradenumb == `i'
replace Swap_coupon_8_date = trade_start_date + 1440 if Tradenumb == `i'
replace Swap_coupon_9_date = trade_start_date + 1620 if Tradenumb == `i'
replace Swap_coupon_10_date = trade_start_date + 1800 if Tradenumb == `i'
replace Swap_coupon_11_date = trade_start_date + 1960 if Tradenumb == `i'
replace Swap_coupon_12_date = trade_start_date + 2160 if Tradenumb == `i'
replace Swap_coupon_13_date = trade_start_date + 2340 if Tradenumb == `i'
replace Swap_coupon_14_date = trade_start_date + 2520 if Tradenumb == `i'
replace Swap_coupon_15_date = trade_start_date + 2700 if Tradenumb == `i'
replace Swap_coupon_16_date = trade_start_date + 2880 if Tradenumb == `i'
replace Swap_coupon_17_date = trade_start_date + 3060 if Tradenumb == `i'
replace Swap_coupon_18_date = trade_start_date + 3240 if Tradenumb == `i'
replace Swap_coupon_19_date = trade_start_date + 3420 if Tradenumb == `i'
replace Swap_coupon_20_date = trade_start_date + 3600 if Tradenumb == `i'
//Schleife?
replace LIBOR_coupon_date = trade_start_date + 90 if Tradenumb == `i' & Date <= trade_start_date+90
replace LIBOR_coupon_date = trade_start_date + 180 if Tradenumb == `i' & Date > trade_start_date+90 & Date <= trade_start_date+180
replace LIBOR_coupon_date = trade_start_date + 270 if Tradenumb == `i' & Date > trade_start_date+180 & Date <= trade_start_date+270
replace LIBOR_coupon_date = trade_start_date + 360 if Tradenumb == `i' & Date > trade_start_date+270 & Date <= trade_start_date+360
replace LIBOR_coupon_date = trade_start_date + 450 if Tradenumb == `i' & Date > trade_start_date+360 & Date <= trade_start_date+450
replace LIBOR_coupon_date = trade_start_date + 540 if Tradenumb == `i' & Date > trade_start_date+450 & Date <= trade_start_date+540
replace LIBOR_coupon_date = trade_start_date + 630 if Tradenumb == `i' & Date > trade_start_date+540 & Date <= trade_start_date+630
replace LIBOR_coupon_date = trade_start_date + 720 if Tradenumb == `i' & Date > trade_start_date+630 & Date <= trade_start_date+720
replace LIBOR_coupon_date = trade_start_date + 810 if Tradenumb == `i' & Date > trade_start_date+720 & Date <= trade_start_date+810
replace LIBOR_coupon_date = trade_start_date + 900 if Tradenumb == `i' & Date > trade_start_date+810 & Date <= trade_start_date+900
replace LIBOR_coupon_date = trade_start_date + 990 if Tradenumb == `i' & Date > trade_start_date+900 & Date <= trade_start_date+990
replace LIBOR_coupon_date = trade_start_date + 1080 if Tradenumb == `i' & Date > trade_start_date+990 & Date <= trade_start_date+1080
replace LIBOR_coupon_date = trade_start_date + 1170 if Tradenumb == `i' & Date > trade_start_date+1080 & Date <= trade_start_date+1170
replace LIBOR_coupon_date = trade_start_date + 1260 if Tradenumb == `i' & Date > trade_start_date+1170 & Date <= trade_start_date+1260
replace LIBOR_coupon_date = trade_start_date + 1350 if Tradenumb == `i' & Date > trade_start_date+1260 & Date <= trade_start_date+1350
replace LIBOR_coupon_date = trade_start_date + 1440 if Tradenumb == `i' & Date > trade_start_date+1350 & Date <= trade_start_date+1440
replace LIBOR_coupon_date = trade_start_date + 1530 if Tradenumb == `i' & Date > trade_start_date+1440 & Date <= trade_start_date+1530
replace LIBOR_coupon_date = trade_start_date + 1620 if Tradenumb == `i' & Date > trade_start_date+1530 & Date <= trade_start_date+1620
replace LIBOR_coupon_date = trade_start_date + 1710 if Tradenumb == `i' & Date > trade_start_date+1620 & Date <= trade_start_date+1710
replace LIBOR_coupon_date = trade_start_date + 1800 if Tradenumb == `i' & Date > trade_start_date+1710 & Date <= trade_start_date+1800
replace LIBOR_coupon_date = trade_start_date + 1890 if Tradenumb == `i' & Date > trade_start_date+1800 & Date <= trade_start_date+1890
replace LIBOR_coupon_date = trade_start_date + 1980 if Tradenumb == `i' & Date > trade_start_date+1890 & Date <= trade_start_date+1980
replace LIBOR_coupon_date = trade_start_date + 2070 if Tradenumb == `i' & Date > trade_start_date+1980 & Date <= trade_start_date+2070
replace LIBOR_coupon_date = trade_start_date + 2160 if Tradenumb == `i' & Date > trade_start_date+2070 & Date <= trade_start_date+2160
replace LIBOR_coupon_date = trade_start_date + 2250 if Tradenumb == `i' & Date > trade_start_date+2160 & Date <= trade_start_date+2250
replace LIBOR_coupon_date = trade_start_date + 2340 if Tradenumb == `i' & Date > trade_start_date+2250 & Date <= trade_start_date+2340
replace LIBOR_coupon_date = trade_start_date + 2430 if Tradenumb == `i' & Date > trade_start_date+2340 & Date <= trade_start_date+2430
replace LIBOR_coupon_date = trade_start_date + 2520 if Tradenumb == `i' & Date > trade_start_date+2430 & Date <= trade_start_date+2520
replace LIBOR_coupon_date = trade_start_date + 2610 if Tradenumb == `i' & Date > trade_start_date+2520 & Date <= trade_start_date+2610
replace LIBOR_coupon_date = trade_start_date + 2700 if Tradenumb == `i' & Date > trade_start_date+2610 & Date <= trade_start_date+2700
replace LIBOR_coupon_date = trade_start_date + 2790 if Tradenumb == `i' & Date > trade_start_date+2700 & Date <= trade_start_date+2790
replace LIBOR_coupon_date = trade_start_date + 2880 if Tradenumb == `i' & Date > trade_start_date+2790 & Date <= trade_start_date+2880
replace LIBOR_coupon_date = trade_start_date + 2970 if Tradenumb == `i' & Date > trade_start_date+2880 & Date <= trade_start_date+2970
replace LIBOR_coupon_date = trade_start_date + 3060 if Tradenumb == `i' & Date > trade_start_date+2970 & Date <= trade_start_date+3060
replace LIBOR_coupon_date = trade_start_date + 3150 if Tradenumb == `i' & Date > trade_start_date+3060 & Date <= trade_start_date+3150
replace LIBOR_coupon_date = trade_start_date + 3240 if Tradenumb == `i' & Date > trade_start_date+3150 & Date <= trade_start_date+3240
replace LIBOR_coupon_date = trade_start_date + 3330 if Tradenumb == `i' & Date > trade_start_date+3240 & Date <= trade_start_date+3330
replace LIBOR_coupon_date = trade_start_date + 3420 if Tradenumb == `i' & Date > trade_start_date+3330 & Date <= trade_start_date+3420
replace LIBOR_coupon_date = trade_start_date + 3510 if Tradenumb == `i' & Date > trade_start_date+3420 & Date <= trade_start_date+3510
replace LIBOR_coupon_date = trade_start_date + 3600 if Tradenumb == `i' & Date > trade_start_date+3510 & Date <= trade_start_date+3600
replace REPO_reset_date = Date[_n-1] if Tradenumb == `i' & Date <= trade_end_date
replace REPO_reset_date =. if Tradenumb ==`i' & Date == trade_start_date
drop trade_start_date trade_end_date
}
}
quietly {
forvalues j = 0/3600 {
replace Treasury_disc_1 = DT__`j' if Treasury_coupon_1_date - Date ==`j'
replace Swap_disc_1 = DS__`j' if Swap_coupon_1_date - Date == `j'
replace Treasury_disc_2 = DT__`j' if Treasury_coupon_2_date - Date == `j'
replace Swap_disc_2 = DS__`j' if Swap_coupon_2_date - Date == `j'
replace Treasury_disc_3 = DT__`j' if Treasury_coupon_3_date - Date == `j'
replace Swap_disc_3 = DS__`j' if Swap_coupon_3_date - Date == `j'
replace Treasury_disc_4 = DT__`j' if Treasury_coupon_4_date - Date == `j' //& `j' <= 720
replace Swap_disc_4 = DS__`j' if Swap_coupon_4_date - Date == `j' //& `j' <= 720
replace Treasury_disc_5 = DT__`j' if Treasury_coupon_5_date - Date ==`j'
replace Swap_disc_5 = DS__`j' if Swap_coupon_5_date - Date == `j'
replace Treasury_disc_6 = DT__`j' if Treasury_coupon_6_date - Date ==`j'
replace Swap_disc_6 = DS__`j' if Swap_coupon_6_date - Date == `j'
replace Treasury_disc_7 = DT__`j' if Treasury_coupon_7_date - Date ==`j'
replace Swap_disc_7 = DS__`j' if Swap_coupon_7_date - Date == `j'
replace Treasury_disc_8 = DT__`j' if Treasury_coupon_8_date - Date ==`j'
replace Swap_disc_8 = DS__`j' if Swap_coupon_8_date - Date == `j'
replace Treasury_disc_9 = DT__`j' if Treasury_coupon_9_date - Date ==`j'
replace Swap_disc_9 = DS__`j' if Swap_coupon_9_date - Date == `j'
replace Treasury_disc_10 = DT__`j' if Treasury_coupon_10_date - Date ==`j'
replace Swap_disc_10 = DS__`j' if Swap_coupon_10_date - Date == `j'
replace Treasury_disc_11 = DT__`j' if Treasury_coupon_11_date - Date ==`j'
replace Swap_disc_11 = DS__`j' if Swap_coupon_11_date - Date == `j'
replace Treasury_disc_12 = DT__`j' if Treasury_coupon_12_date - Date ==`j'
replace Swap_disc_12 = DS__`j' if Swap_coupon_12_date - Date == `j'
replace Treasury_disc_13 = DT__`j' if Treasury_coupon_13_date - Date ==`j'
replace Swap_disc_13 = DS__`j' if Swap_coupon_13_date - Date == `j'
replace Treasury_disc_14 = DT__`j' if Treasury_coupon_14_date - Date ==`j'
replace Swap_disc_14 = DS__`j' if Swap_coupon_14_date - Date == `j'
replace Treasury_disc_15 = DT__`j' if Treasury_coupon_15_date - Date ==`j'
replace Swap_disc_15 = DS__`j' if Swap_coupon_15_date - Date == `j'
replace Treasury_disc_16 = DT__`j' if Treasury_coupon_16_date - Date ==`j'
replace Swap_disc_16 = DS__`j' if Swap_coupon_16_date - Date == `j'
replace Treasury_disc_17 = DT__`j' if Treasury_coupon_17_date - Date ==`j'
replace Swap_disc_17 = DS__`j' if Swap_coupon_17_date - Date == `j'
replace Treasury_disc_18 = DT__`j' if Treasury_coupon_18_date - Date ==`j'
replace Swap_disc_18 = DS__`j' if Swap_coupon_18_date - Date == `j'
replace Treasury_disc_19 = DT__`j' if Treasury_coupon_19_date - Date ==`j'
replace Swap_disc_19 = DS__`j' if Swap_coupon_19_date - Date == `j'
replace Treasury_disc_20 = DT__`j' if Treasury_coupon_20_date - Date ==`j'
replace Swap_disc_20 = DS__`j' if Swap_coupon_20_date - Date == `j'
}
}
quietly {
forvalues i = 0/3600 {
drop DT__`i' DS__`i'
}
}
}
save TF_Short_10Y_5BP_US_last.dta
I need your help! I am working with very big data files (~20Gb) containing around 1 million observations and 15 to 20 000 variables. I'm trying to reduce the size of the data file to around 100 variables max. However, when I loop through my data and try to subsequently reduce the size, Stata takes way too long to perform the tasks. Maybe some of you have an idea of how to speed up the code and get to the same outcome! All help is much appreciated

Here is the code I'm currently running...
// US 10Y 5BP SHORT
clear all
quietly {
use TF_Short_10Y_5BP_US_end.dta
gen Treasury_coupon_1 = Treasury
gen Treasury_coupon_2 = Treasury
gen Treasury_coupon_3 = Treasury
gen Treasury_coupon_4 = Treasury
gen Treasury_coupon_5 = Treasury
gen Treasury_coupon_6 = Treasury
gen Treasury_coupon_7 = Treasury
gen Treasury_coupon_8 = Treasury
gen Treasury_coupon_9 = Treasury
gen Treasury_coupon_10 = Treasury
gen Treasury_coupon_11 = Treasury
gen Treasury_coupon_12 = Treasury
gen Treasury_coupon_13 = Treasury
gen Treasury_coupon_14 = Treasury
gen Treasury_coupon_15 = Treasury
gen Treasury_coupon_16 = Treasury
gen Treasury_coupon_17 = Treasury
gen Treasury_coupon_18 = Treasury
gen Treasury_coupon_19 = Treasury
gen Treasury_coupon_20 = Treasury + 100
gen Swap_coupon_1 = Swap
gen Swap_coupon_2 = Swap
gen Swap_coupon_3 = Swap
gen Swap_coupon_4 = Swap
gen Swap_coupon_5 = Swap
gen Swap_coupon_6 = Swap
gen Swap_coupon_7 = Swap
gen Swap_coupon_8 = Swap
gen Swap_coupon_9 = Swap
gen Swap_coupon_10 = Swap
gen Swap_coupon_11 = Swap
gen Swap_coupon_12 = Swap
gen Swap_coupon_13 = Swap
gen Swap_coupon_14 = Swap
gen Swap_coupon_15 = Swap
gen Swap_coupon_16 = Swap
gen Swap_coupon_17 = Swap
gen Swap_coupon_18 = Swap
gen Swap_coupon_19 = Swap
gen Swap_coupon_20 = Swap + 100
gen LIBOR_coupon = LIBOR + 100
gen Treasury_disc_1 = 1
gen Treasury_disc_2 = 1
gen Treasury_disc_3 = 1
gen Treasury_disc_4 = 1
gen Treasury_disc_5 = 1
gen Treasury_disc_6 = 1
gen Treasury_disc_7 = 1
gen Treasury_disc_8 = 1
gen Treasury_disc_9 = 1
gen Treasury_disc_10 = 1
gen Treasury_disc_11 = 1
gen Treasury_disc_12 = 1
gen Treasury_disc_13 = 1
gen Treasury_disc_14 = 1
gen Treasury_disc_15 = 1
gen Treasury_disc_16 = 1
gen Treasury_disc_17 = 1
gen Treasury_disc_18 = 1
gen Treasury_disc_19 = 1
gen Treasury_disc_20 = 1
gen Swap_disc_1 = 1
gen Swap_disc_2 = 1
gen Swap_disc_3 = 1
gen Swap_disc_4 = 1
gen Swap_disc_5 = 1
gen Swap_disc_6 = 1
gen Swap_disc_7 = 1
gen Swap_disc_8 = 1
gen Swap_disc_9 = 1
gen Swap_disc_10 = 1
gen Swap_disc_11 = 1
gen Swap_disc_12 = 1
gen Swap_disc_13 = 1
gen Swap_disc_14 = 1
gen Swap_disc_15 = 1
gen Swap_disc_16 = 1
gen Swap_disc_17 = 1
gen Swap_disc_18 = 1
gen Swap_disc_19 = 1
gen Swap_disc_20 = 1
gen Treasury_coupon_1_date =.
gen Treasury_coupon_2_date =.
gen Treasury_coupon_3_date =.
gen Treasury_coupon_4_date =.
gen Treasury_coupon_5_date =.
gen Treasury_coupon_6_date =.
gen Treasury_coupon_7_date =.
gen Treasury_coupon_8_date =.
gen Treasury_coupon_9_date =.
gen Treasury_coupon_10_date =.
gen Treasury_coupon_11_date =.
gen Treasury_coupon_12_date =.
gen Treasury_coupon_13_date =.
gen Treasury_coupon_14_date =.
gen Treasury_coupon_15_date =.
gen Treasury_coupon_16_date =.
gen Treasury_coupon_17_date =.
gen Treasury_coupon_18_date =.
gen Treasury_coupon_19_date =.
gen Treasury_coupon_20_date =.
gen Swap_coupon_1_date =.
gen Swap_coupon_2_date =.
gen Swap_coupon_3_date =.
gen Swap_coupon_4_date =.
gen Swap_coupon_5_date =.
gen Swap_coupon_6_date =.
gen Swap_coupon_7_date =.
gen Swap_coupon_8_date =.
gen Swap_coupon_9_date =.
gen Swap_coupon_10_date =.
gen Swap_coupon_11_date =.
gen Swap_coupon_12_date =.
gen Swap_coupon_13_date =.
gen Swap_coupon_14_date =.
gen Swap_coupon_15_date =.
gen Swap_coupon_16_date =.
gen Swap_coupon_17_date =.
gen Swap_coupon_18_date =.
gen Swap_coupon_19_date =.
gen Swap_coupon_20_date =.
gen LIBOR_coupon_date=.
gen REPO_reset_date =.
quietly {
forvalues i = 1/2119 {
egen trade_start_date = min(Date) if Tradenumb == `i'
egen trade_end_date = max(Date) if Tradenumb == `i'
replace Treasury_coupon_1_date = trade_start_date + 180 if Tradenumb == `i'
replace Treasury_coupon_2_date = trade_start_date + 360 if Tradenumb == `i'
replace Treasury_coupon_3_date = trade_start_date + 540 if Tradenumb == `i'
replace Treasury_coupon_4_date = trade_start_date + 720 if Tradenumb == `i'
replace Treasury_coupon_5_date = trade_start_date + 900 if Tradenumb == `i'
replace Treasury_coupon_6_date = trade_start_date + 1080 if Tradenumb == `i'
replace Treasury_coupon_7_date = trade_start_date + 1260 if Tradenumb == `i'
replace Treasury_coupon_8_date = trade_start_date + 1440 if Tradenumb == `i'
replace Treasury_coupon_9_date = trade_start_date + 1620 if Tradenumb == `i'
replace Treasury_coupon_10_date = trade_start_date + 1800 if Tradenumb == `i'
replace Treasury_coupon_11_date = trade_start_date + 1960 if Tradenumb == `i'
replace Treasury_coupon_12_date = trade_start_date + 2160 if Tradenumb == `i'
replace Treasury_coupon_13_date = trade_start_date + 2340 if Tradenumb == `i'
replace Treasury_coupon_14_date = trade_start_date + 2520 if Tradenumb == `i'
replace Treasury_coupon_15_date = trade_start_date + 2700 if Tradenumb == `i'
replace Treasury_coupon_16_date = trade_start_date + 2880 if Tradenumb == `i'
replace Treasury_coupon_17_date = trade_start_date + 3060 if Tradenumb == `i'
replace Treasury_coupon_18_date = trade_start_date + 3240 if Tradenumb == `i'
replace Treasury_coupon_19_date = trade_start_date + 3420 if Tradenumb == `i'
replace Treasury_coupon_20_date = trade_start_date + 3600 if Tradenumb == `i'
replace Swap_coupon_1_date = trade_start_date + 180 if Tradenumb == `i'
replace Swap_coupon_2_date = trade_start_date + 360 if Tradenumb == `i'
replace Swap_coupon_3_date = trade_start_date + 540 if Tradenumb == `i'
replace Swap_coupon_4_date = trade_start_date + 720 if Tradenumb == `i'
replace Swap_coupon_5_date = trade_start_date + 900 if Tradenumb == `i'
replace Swap_coupon_6_date = trade_start_date + 1080 if Tradenumb == `i'
replace Swap_coupon_7_date = trade_start_date + 1260 if Tradenumb == `i'
replace Swap_coupon_8_date = trade_start_date + 1440 if Tradenumb == `i'
replace Swap_coupon_9_date = trade_start_date + 1620 if Tradenumb == `i'
replace Swap_coupon_10_date = trade_start_date + 1800 if Tradenumb == `i'
replace Swap_coupon_11_date = trade_start_date + 1960 if Tradenumb == `i'
replace Swap_coupon_12_date = trade_start_date + 2160 if Tradenumb == `i'
replace Swap_coupon_13_date = trade_start_date + 2340 if Tradenumb == `i'
replace Swap_coupon_14_date = trade_start_date + 2520 if Tradenumb == `i'
replace Swap_coupon_15_date = trade_start_date + 2700 if Tradenumb == `i'
replace Swap_coupon_16_date = trade_start_date + 2880 if Tradenumb == `i'
replace Swap_coupon_17_date = trade_start_date + 3060 if Tradenumb == `i'
replace Swap_coupon_18_date = trade_start_date + 3240 if Tradenumb == `i'
replace Swap_coupon_19_date = trade_start_date + 3420 if Tradenumb == `i'
replace Swap_coupon_20_date = trade_start_date + 3600 if Tradenumb == `i'
//Schleife?
replace LIBOR_coupon_date = trade_start_date + 90 if Tradenumb == `i' & Date <= trade_start_date+90
replace LIBOR_coupon_date = trade_start_date + 180 if Tradenumb == `i' & Date > trade_start_date+90 & Date <= trade_start_date+180
replace LIBOR_coupon_date = trade_start_date + 270 if Tradenumb == `i' & Date > trade_start_date+180 & Date <= trade_start_date+270
replace LIBOR_coupon_date = trade_start_date + 360 if Tradenumb == `i' & Date > trade_start_date+270 & Date <= trade_start_date+360
replace LIBOR_coupon_date = trade_start_date + 450 if Tradenumb == `i' & Date > trade_start_date+360 & Date <= trade_start_date+450
replace LIBOR_coupon_date = trade_start_date + 540 if Tradenumb == `i' & Date > trade_start_date+450 & Date <= trade_start_date+540
replace LIBOR_coupon_date = trade_start_date + 630 if Tradenumb == `i' & Date > trade_start_date+540 & Date <= trade_start_date+630
replace LIBOR_coupon_date = trade_start_date + 720 if Tradenumb == `i' & Date > trade_start_date+630 & Date <= trade_start_date+720
replace LIBOR_coupon_date = trade_start_date + 810 if Tradenumb == `i' & Date > trade_start_date+720 & Date <= trade_start_date+810
replace LIBOR_coupon_date = trade_start_date + 900 if Tradenumb == `i' & Date > trade_start_date+810 & Date <= trade_start_date+900
replace LIBOR_coupon_date = trade_start_date + 990 if Tradenumb == `i' & Date > trade_start_date+900 & Date <= trade_start_date+990
replace LIBOR_coupon_date = trade_start_date + 1080 if Tradenumb == `i' & Date > trade_start_date+990 & Date <= trade_start_date+1080
replace LIBOR_coupon_date = trade_start_date + 1170 if Tradenumb == `i' & Date > trade_start_date+1080 & Date <= trade_start_date+1170
replace LIBOR_coupon_date = trade_start_date + 1260 if Tradenumb == `i' & Date > trade_start_date+1170 & Date <= trade_start_date+1260
replace LIBOR_coupon_date = trade_start_date + 1350 if Tradenumb == `i' & Date > trade_start_date+1260 & Date <= trade_start_date+1350
replace LIBOR_coupon_date = trade_start_date + 1440 if Tradenumb == `i' & Date > trade_start_date+1350 & Date <= trade_start_date+1440
replace LIBOR_coupon_date = trade_start_date + 1530 if Tradenumb == `i' & Date > trade_start_date+1440 & Date <= trade_start_date+1530
replace LIBOR_coupon_date = trade_start_date + 1620 if Tradenumb == `i' & Date > trade_start_date+1530 & Date <= trade_start_date+1620
replace LIBOR_coupon_date = trade_start_date + 1710 if Tradenumb == `i' & Date > trade_start_date+1620 & Date <= trade_start_date+1710
replace LIBOR_coupon_date = trade_start_date + 1800 if Tradenumb == `i' & Date > trade_start_date+1710 & Date <= trade_start_date+1800
replace LIBOR_coupon_date = trade_start_date + 1890 if Tradenumb == `i' & Date > trade_start_date+1800 & Date <= trade_start_date+1890
replace LIBOR_coupon_date = trade_start_date + 1980 if Tradenumb == `i' & Date > trade_start_date+1890 & Date <= trade_start_date+1980
replace LIBOR_coupon_date = trade_start_date + 2070 if Tradenumb == `i' & Date > trade_start_date+1980 & Date <= trade_start_date+2070
replace LIBOR_coupon_date = trade_start_date + 2160 if Tradenumb == `i' & Date > trade_start_date+2070 & Date <= trade_start_date+2160
replace LIBOR_coupon_date = trade_start_date + 2250 if Tradenumb == `i' & Date > trade_start_date+2160 & Date <= trade_start_date+2250
replace LIBOR_coupon_date = trade_start_date + 2340 if Tradenumb == `i' & Date > trade_start_date+2250 & Date <= trade_start_date+2340
replace LIBOR_coupon_date = trade_start_date + 2430 if Tradenumb == `i' & Date > trade_start_date+2340 & Date <= trade_start_date+2430
replace LIBOR_coupon_date = trade_start_date + 2520 if Tradenumb == `i' & Date > trade_start_date+2430 & Date <= trade_start_date+2520
replace LIBOR_coupon_date = trade_start_date + 2610 if Tradenumb == `i' & Date > trade_start_date+2520 & Date <= trade_start_date+2610
replace LIBOR_coupon_date = trade_start_date + 2700 if Tradenumb == `i' & Date > trade_start_date+2610 & Date <= trade_start_date+2700
replace LIBOR_coupon_date = trade_start_date + 2790 if Tradenumb == `i' & Date > trade_start_date+2700 & Date <= trade_start_date+2790
replace LIBOR_coupon_date = trade_start_date + 2880 if Tradenumb == `i' & Date > trade_start_date+2790 & Date <= trade_start_date+2880
replace LIBOR_coupon_date = trade_start_date + 2970 if Tradenumb == `i' & Date > trade_start_date+2880 & Date <= trade_start_date+2970
replace LIBOR_coupon_date = trade_start_date + 3060 if Tradenumb == `i' & Date > trade_start_date+2970 & Date <= trade_start_date+3060
replace LIBOR_coupon_date = trade_start_date + 3150 if Tradenumb == `i' & Date > trade_start_date+3060 & Date <= trade_start_date+3150
replace LIBOR_coupon_date = trade_start_date + 3240 if Tradenumb == `i' & Date > trade_start_date+3150 & Date <= trade_start_date+3240
replace LIBOR_coupon_date = trade_start_date + 3330 if Tradenumb == `i' & Date > trade_start_date+3240 & Date <= trade_start_date+3330
replace LIBOR_coupon_date = trade_start_date + 3420 if Tradenumb == `i' & Date > trade_start_date+3330 & Date <= trade_start_date+3420
replace LIBOR_coupon_date = trade_start_date + 3510 if Tradenumb == `i' & Date > trade_start_date+3420 & Date <= trade_start_date+3510
replace LIBOR_coupon_date = trade_start_date + 3600 if Tradenumb == `i' & Date > trade_start_date+3510 & Date <= trade_start_date+3600
replace REPO_reset_date = Date[_n-1] if Tradenumb == `i' & Date <= trade_end_date
replace REPO_reset_date =. if Tradenumb ==`i' & Date == trade_start_date
drop trade_start_date trade_end_date
}
}
quietly {
forvalues j = 0/3600 {
replace Treasury_disc_1 = DT__`j' if Treasury_coupon_1_date - Date ==`j'
replace Swap_disc_1 = DS__`j' if Swap_coupon_1_date - Date == `j'
replace Treasury_disc_2 = DT__`j' if Treasury_coupon_2_date - Date == `j'
replace Swap_disc_2 = DS__`j' if Swap_coupon_2_date - Date == `j'
replace Treasury_disc_3 = DT__`j' if Treasury_coupon_3_date - Date == `j'
replace Swap_disc_3 = DS__`j' if Swap_coupon_3_date - Date == `j'
replace Treasury_disc_4 = DT__`j' if Treasury_coupon_4_date - Date == `j' //& `j' <= 720
replace Swap_disc_4 = DS__`j' if Swap_coupon_4_date - Date == `j' //& `j' <= 720
replace Treasury_disc_5 = DT__`j' if Treasury_coupon_5_date - Date ==`j'
replace Swap_disc_5 = DS__`j' if Swap_coupon_5_date - Date == `j'
replace Treasury_disc_6 = DT__`j' if Treasury_coupon_6_date - Date ==`j'
replace Swap_disc_6 = DS__`j' if Swap_coupon_6_date - Date == `j'
replace Treasury_disc_7 = DT__`j' if Treasury_coupon_7_date - Date ==`j'
replace Swap_disc_7 = DS__`j' if Swap_coupon_7_date - Date == `j'
replace Treasury_disc_8 = DT__`j' if Treasury_coupon_8_date - Date ==`j'
replace Swap_disc_8 = DS__`j' if Swap_coupon_8_date - Date == `j'
replace Treasury_disc_9 = DT__`j' if Treasury_coupon_9_date - Date ==`j'
replace Swap_disc_9 = DS__`j' if Swap_coupon_9_date - Date == `j'
replace Treasury_disc_10 = DT__`j' if Treasury_coupon_10_date - Date ==`j'
replace Swap_disc_10 = DS__`j' if Swap_coupon_10_date - Date == `j'
replace Treasury_disc_11 = DT__`j' if Treasury_coupon_11_date - Date ==`j'
replace Swap_disc_11 = DS__`j' if Swap_coupon_11_date - Date == `j'
replace Treasury_disc_12 = DT__`j' if Treasury_coupon_12_date - Date ==`j'
replace Swap_disc_12 = DS__`j' if Swap_coupon_12_date - Date == `j'
replace Treasury_disc_13 = DT__`j' if Treasury_coupon_13_date - Date ==`j'
replace Swap_disc_13 = DS__`j' if Swap_coupon_13_date - Date == `j'
replace Treasury_disc_14 = DT__`j' if Treasury_coupon_14_date - Date ==`j'
replace Swap_disc_14 = DS__`j' if Swap_coupon_14_date - Date == `j'
replace Treasury_disc_15 = DT__`j' if Treasury_coupon_15_date - Date ==`j'
replace Swap_disc_15 = DS__`j' if Swap_coupon_15_date - Date == `j'
replace Treasury_disc_16 = DT__`j' if Treasury_coupon_16_date - Date ==`j'
replace Swap_disc_16 = DS__`j' if Swap_coupon_16_date - Date == `j'
replace Treasury_disc_17 = DT__`j' if Treasury_coupon_17_date - Date ==`j'
replace Swap_disc_17 = DS__`j' if Swap_coupon_17_date - Date == `j'
replace Treasury_disc_18 = DT__`j' if Treasury_coupon_18_date - Date ==`j'
replace Swap_disc_18 = DS__`j' if Swap_coupon_18_date - Date == `j'
replace Treasury_disc_19 = DT__`j' if Treasury_coupon_19_date - Date ==`j'
replace Swap_disc_19 = DS__`j' if Swap_coupon_19_date - Date == `j'
replace Treasury_disc_20 = DT__`j' if Treasury_coupon_20_date - Date ==`j'
replace Swap_disc_20 = DS__`j' if Swap_coupon_20_date - Date == `j'
}
}
quietly {
forvalues i = 0/3600 {
drop DT__`i' DS__`i'
}
}
}
save TF_Short_10Y_5BP_US_last.dta
Comment