Hello there, I am new to the STATA Forum and I am hoping you could help me with generating a rolling window Fourier Transform and dydx. I have written a simple do-loop (see below) but it takes a while to generate if the sample size is very large. I wonder if there is a way to make it more efficient. I tried using "rolling" in STATA but it doesn't seem working.
clear
set obs 25600
gen t=(_n-1)*(2*_pi)/25600
gen y=exp(-(cos(t))^2)*(sin(2*t)+2*cos(4*t)+0.4*sin(t)*sin(50 *t))
egen seq = seq()
tsset seq
local x = 20
while `x' <= _N {
qui dydx y t if seq <= `x', gen(y1)
qui fft y if seq <= `x' & seq > `x' - 15, gen(v u)
if (`x' == 20) {
qui gen Slope_y = y1 if seq == `x'
qui gen fft1 = v if seq == `x'
}
else {
qui replace Slope_y = y1 if seq == `x'
qui replace fft1 = v if seq == `x'
}
qui drop y1 u v
local x = `x' + 1
dis `x'
}
Much appreciated.
Raymond
clear
set obs 25600
gen t=(_n-1)*(2*_pi)/25600
gen y=exp(-(cos(t))^2)*(sin(2*t)+2*cos(4*t)+0.4*sin(t)*sin(50 *t))
egen seq = seq()
tsset seq
local x = 20
while `x' <= _N {
qui dydx y t if seq <= `x', gen(y1)
qui fft y if seq <= `x' & seq > `x' - 15, gen(v u)
if (`x' == 20) {
qui gen Slope_y = y1 if seq == `x'
qui gen fft1 = v if seq == `x'
}
else {
qui replace Slope_y = y1 if seq == `x'
qui replace fft1 = v if seq == `x'
}
qui drop y1 u v
local x = `x' + 1
dis `x'
}
Much appreciated.
Raymond
Comment