Hi -- I've written a brief ado file to spit back characteristics of parametrized sinusoids (specifically, a 4-term Fourier series). The code is below. The mata code works fine when I run it on it's own --- say with a= .0005769, b= .0422043, c= .0131597, d= -.0168322 --- as an individual mata session. All four outputs (minimum, maximum, amplitude, lowpoint) are calculated, and all four also stored into a stata matrix that I can access after I end mata. However, when I call the ado as in the context at the bottom, it exports all matrices except lowpoint. I think I'm using minindex correctly --- it's underlined in red in the ado file whenever I store the index as anything but the letter i, but it does seem to work despite that --- and again, lowpoint *does* export to a stata matrix in individual mata sessions. Just now when run through the ado file. Any idea what's going on? Thank you!
** ADO FILE:
** CONTEXT FOR USE
** ADO FILE:
Code:
/* User written command by Leah E. M. Bevis */
/* December 2018 */
/* Input: coefficients (a,b,c,d) from the terms of this 4-term Fourier series: */
/* y = k + a*cos(2*pi*t/T1) + b*sin(2*pi*t/T1) + c*cos(2*pi*t/T2) + d*cos(2*pi*t/T2) */
/* Output: maximum, minimum, amplitude, index of lowest point */
program sinusoid
version 14.2
args a b c d
mata: FourierAmp(`a',`b',`c',`d')
end
version 14.2
mata:
void FourierAmp(a, b, c, d) {
t = (1::365)
t=t/365
T1=1
omega1=2*pi()/T1
T2=1/2
omega2=2*pi()/T2
y=a*cos(omega1*t) + b*sin(omega1*t) + c*cos(omega2*t) + d*sin(omega2*t)
lowpoint=999
w=999
minindex(y,1,lowpoint,w)
minimum=min(y)
maximum=max(y)
amplitude=maximum-minimum
st_matrix("minimum", minimum)
st_matrix("maximum", maximum)
st_matrix("amplitude", amplitude)
st_matrix("lowpoint", lowpoint)
}
end
** CONTEXT FOR USE
Code:
reg Y csmnth snmnth csmnth2 snmnth2
local a = _b[csmnth]
local b = _b[snmnth]
local c = _b[csmnth2]
local d = _b[snmnth2]
sinusoid `a' `b' `c' `d'
mat lis amplitude
mat lis minimum
mat lis maximum
mat lis lowpoint

Comment