Hello
I have a set of time-series variables and I need to compute the correlation coefficients (rho) between them for each point in time tn, using only the information available at that time tn. Giving an exemple: if my data base had two variables, x1 and x2, I need to compute rho for t1, t2, t3,...,tn,..., tN.
I used a loop with forvalues:
forvalues t=1/148 { //N=148 is my sample size
correl x1 x2
}
This allowed me to get N=148 correlation matrices. My plan is to use the scalars r(rho) from each of them to construct a variable that gives me the correlation coefficient between x1 and x2 over time. However, as my sample is going to increase (because new information becomes available), I don't want to fix the amount of times the loop runs (currently, 148). I want it to increase as the sample size increases.
Is there any way of using a loop to create this variable? Or any other means of doing it?
Thank you very much in advance!
I have a set of time-series variables and I need to compute the correlation coefficients (rho) between them for each point in time tn, using only the information available at that time tn. Giving an exemple: if my data base had two variables, x1 and x2, I need to compute rho for t1, t2, t3,...,tn,..., tN.
I used a loop with forvalues:
forvalues t=1/148 { //N=148 is my sample size
correl x1 x2
}
This allowed me to get N=148 correlation matrices. My plan is to use the scalars r(rho) from each of them to construct a variable that gives me the correlation coefficient between x1 and x2 over time. However, as my sample is going to increase (because new information becomes available), I don't want to fix the amount of times the loop runs (currently, 148). I want it to increase as the sample size increases.
Is there any way of using a loop to create this variable? Or any other means of doing it?
Thank you very much in advance!
Comment