# lagTrim¶

## Purpose¶

Lags (or leads) a vector a specified number of time periods and removes the incomplete rows.

## Format¶

y = lagTrim(y, t)
Parameters: y (Nx1 vector) – data t (scalar or Px1 vector) – number of time periods. y (NxP matrix) – y lagged t periods.

## Examples¶

### Single lag¶

// Specify number of lags
nlags = 2;

// Define y matrix
y = { 1.4, 2.7, 3.1, 2.9, 3.2, 2.5, 2.8 };

// Lag y nlags number of lags
// and trim missing values
y_lag = lagTrim(y, nlags);


will assign y_lag to equal:

1.4
2.7
3.1
2.9
3.2


### Multiple lags¶

If the number of time periods to lag is a Px1 column vector, then the output matrix with be an NxP matrix where each column contains one of the lags. For example, changing the nlags variable from the example above to be a 3x1 column vector like this:

// Specify to compute the 1, 2, and 3 lags
nlags = { 1, 2, 3 };

// Define y vector
y = { 1.4, 2.7, 3.1, 2.9, 3.2, 2.5, 2.8 };

// Compute the 1, 2, and 3 lags of y
// and trim missing values
y_lag = lagTrim(y, nlags);


will assign lag_mat to equal:

3.1      2.7      1.4
2.9      3.1      2.7
3.2      2.9      3.1
2.5      3.2      2.9


If the number of time periods to lag is a Px1 column vector, then the output matrix with be an NxP matrix where each column contains one of the lags. For example, changing the nlags variable from the example above to be a 3x1 column vector like this:

// Specify nlags to find
// the 1st and 2nd lead
// and 3rd lag of y
nlags = { -1, -2, 3 };

// Define y vector
y = { 1.4, 2.7, 3.1, 2.9, 3.2, 2.5, 2.8 };

// Lag y using nlags
y_lag = lagTrim(y, nlags);


will assign lag_mat to equal:

3.2      2.5      1.4
2.5      2.8      2.7


## Remarks¶

Functions lagn()