# Lag

Lag shifts your features on a partition index, creating a lookback feature offset by an amount. Lag supports generating multiple lags in one transform by generating each unique combination of columns and amounts from your inputs.

## Parameters

| Name      | Type         | Description                                                                                                                                         | Is Optional |
| --------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| columns   | column\_list | names of column(s) you want to lag                                                                                                                  |             |
| amounts   | int\_list    | Magnitude of amounts you want to use for the lag. Positive values result in a historical offset; negative amounts result in forward-looking offset. |             |
| partition | column\_list | name of column(s) to partition by for the lag                                                                                                       | True        |
| order\_by | column\_list | name of column(s) to order by in the final data set                                                                                                 | True        |

## Example

```python
ds = rasgo.get.dataset(id)

ds2 = ds.lag(columns=['OPEN', 'CLOSE'], amounts=[1,2,3,7], order_by=['DATE, 'TICKER'], partition=['TICKER'])
ds2.preview()
```

## Source Code

{% embed url="<https://github.com/rasgointelligence/RasgoTransforms/blob/main/rasgotransforms/rasgotransforms/transforms/lag/lag.sql>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rasgoml.com/rasgo-docs/rasgo-0.1/all-transforms/lag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
