# Multiple lag() in TimeSeries doesn't work in one line

**URL:** <https://discourse.julialang.org/t/multiple-lag-in-timeseries-doesnt-work-in-one-line/46154>\
**Category:** Data\
**Tags:** question, dataframes, time-series\
**Created:** [September 6, 2020, 6:29pm UTC](https://discourse.julialang.org/t/multiple-lag-in-timeseries-doesnt-work-in-one-line/46154 "2020-09-06T18:29:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaepil\_Lee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaepil_lee/32/9146_2.png) [@Jaepil\_Lee](https://discourse.julialang.org/u/Jaepil_Lee)\
**Post date:** [September 6, 2020, 6:29pm UTC](https://discourse.julialang.org/t/multiple-lag-in-timeseries-doesnt-work-in-one-line/46154/1 "2020-09-06T18:29:01Z")

</div>

Hello Julia users!

I have been playing with `TimeSeries` package and found one operation that doesn’t make much sense to me. I know that applying `lag()` to a Tx1 `TimeArray` A creates a (T-1)x1 `TimeArray` and `lag(A)./A` creates a (T-1)x1 `TimeArray`. However, doing this to different `TimeArrays` in one line does not work. Please have a look at the code below for illustration:

```julia
using InstantiateFromURL; github_project("QuantEcon/quantecon-notebooks-julia", version = "0.8.0")
using LinearAlgebra, Statistics, Distributions, Random
using CSV, DataFrames
using TimeSeries

t = collect(Date(1998, 1, 1):Month(1):Date(2000, 2, 1))
v1 = randn(26)
v2 = randn(26)
df = DataFrame()
df = DataFrame(x=v1,y=v2,date=t)
tArray = TimeArray(df,timestamp=:date)

x= tArray.x
y= tArray.y
A= x./lag(x)
B= lag(y)./y

C= A.*B
z = (x./lag(x)).*(lag(y)./y)strong text

```

`C` takes `25×1 TimeArray{Float64,1,Date,Array{Float64,1}}`, a result I wanted. However, `C` returns an error:

```julia
DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths 25 and 26")

```

Is this behavior a known issue? Or is there something I am missing that it makes sense that it should not work?

Thank you for your input!

---

<div class="post-metadata">

**Author:** ![Jaepil\_Lee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaepil_lee/32/9146_2.png) [@Jaepil\_Lee](https://discourse.julialang.org/u/Jaepil_Lee)\
**Post date:** [September 6, 2020, 6:39pm UTC](https://discourse.julialang.org/t/multiple-lag-in-timeseries-doesnt-work-in-one-line/46154/2 "2020-09-06T18:39:31Z")

</div>

PS: I immediately found a workaround, `z = (x./lag(x,padding=true)).*(lag(y,padding=true)./y)`, to manually set `lag()` to create the vector of same size in all `x`, `lag(x)`, `y`, `lag(y)`. However, since `C` and `z` are essentially the same, I expect both to produce the same result. If you know why it is designed to return an error, please let me know!
