Here is a simple script that creates a new lag column based upon the a specified number of weeks.
Names Default To Here( 1 );
dt = Current Data Table();
dtTemp = dt << Subset(invisible, All rows, columns( :Date, :Yl ), output table("Lag Table") );
dtTemp:Yl << set name("4 Week Lag Y1");
dtTemp << New Column( "Lagged Date ", formula(:Date), format("m/d/y",10));
For Each Row(
dtTemp:Date = dtTemp:Date + In weeks(4);
);
dtJoined = dt << Join(
With( dtTemp ),
By Matching Columns( :Date = :Date ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Merge Same Name Columns( 1 ),
Match Flag( 0 )
);
close( dtTemp, nosave );
dtJointed = Bivariate(
Y( :Yl ),
X( :Name( "4 Week Lag Y1" ) ),
Fit Line( {Line Color( "Medium Dark Red" )} )
);
Jim