Home →
Techniques and Tips →
StatTools →
**Cross Correlation with Lag for Two Variables**

**Applies to:** StatTools 5.x–7.x

I need to run cross-correlation with lag for two variables. In StatTools, I was able to generate lags and then use the correlation function. However, the lags are positives and not negatives. To run the correlation for negative lags, I have to run lags for the other variable and then correlate, which makes it a little cumbersome, two-step process. Is there a better way?

It's true that negative lags are not available in the Lag procedure of StatTools. The only way to accomplish the task in StatTools, if you limit yourself to menu commands, involves running the Lag procedure twice, separately for each variable (X and Y), as follows:

- Use the StatTools Lag procedure to create shifted versions of Y (Y1, Y2, Y3, ...).
- Use the StatTools Correlation and Covariance procedure to correlate X with Y, Y1, Y2, Y3, .... That gives you positive lags, which is only half of the task.
- To get negative lags, create lagged versions of X (X1, X2, X3, ...) and run Correlation and Covariance between Y and all the X's.

Instead of doing that, you might prefer to have more functionality available in the Lag procedure to begin with. You would like to get both positive and negative lags in the Lag procedure, say -Y3, -Y2, -Y1, Y1, Y2, Y3. Then you could get correlations between X and this list, in one operation.

A good option, if you will have to do this more than once, is to use the automation interface of StatTools, as described in Help » Developer Kit » Help. Using that interface, you can write VBA code that will perform the cross-correlation with lags in one step. Your code would automate the numbered steps above, creating lagged variables with positive and negative lags and then running the Correlation and Covariance procedure. An item can be added to the ribbon to launch the code. If you have programming expertise, you can set this up yourself; or our Custom Development department can assist you. For Custom Development, please contact your Palisade sales office.

Last edited: 2016-03-11

This page was: Helpful |
Not Helpful