On Fri, 26 Dec 2014, Daniel Bencik wrote:
I have several measures of volatility v1, v2, v3 and their 5-day and
22-day
averages (v1_5, v1_22, etc.) loaded into the session. What I would like is to
write a loop over the explained and explanatory variables so that I have one
code for OLS estimation into which I just feed different data. The pseudocode
should look something like this
strings explainedVars = array(3)
explainedVars[1] = "v1"
explainedVars[2] = "v2"
explainedVars[3] = "v3"
strings explanatoryVars = array(9)
explanatoryVars[1] = "v1(-1)"
explanatoryVars[2] = "v1_5(-1)"
explanatoryVars[3] = "v1_22(-1)"
...
explanatoryVars[9] = "v3_22(-1)"
loop i = 1 to 3
loop j = 1 to 9
ols explainedVars[i] explanatoryVars[j]
endloop
endloop
The OLS line is the one that is not working for me, I do not know how to tell
the estimation command that the string explainedVars[i] should be taken as a
series name. The problem is naturally a simplified version of the real
problem.
Arrays of strings are not the right tool for the job here; you should
use lists. Suppose your "explainedVars" are all put in a list named Y
and your "explanatoryVars" in a list named X. Then this would do the
analysis:
<hansl>
loop foreach i Y -q
loop foreach j X -q
list reglist = Y[i] 0 X[j]
ols reglist
endloop
endloop
</hansl>
Allin Cottrell