# Rolling regression with coeffs fixed over time periods

**URL:** <https://discourse.pymc.io/t/rolling-regression-with-coeffs-fixed-over-time-periods/10777>\
**Category:** v3\
**Tags:** modeling\
**Created:** [November 8, 2022, 8:43am UTC](https://discourse.pymc.io/t/rolling-regression-with-coeffs-fixed-over-time-periods/10777 "2022-11-08T08:43:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nic\_Fit](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/nic_fit/32/5806_2.png) [@Nic\_Fit](https://discourse.pymc.io/u/Nic_Fit)\
**Post date:** [November 8, 2022, 8:43am UTC](https://discourse.pymc.io/t/rolling-regression-with-coeffs-fixed-over-time-periods/10777/1 "2022-11-08T08:43:50Z")

</div>

Hi guys,

I have a large data set “factors” with rough shape (2.4mio, 1200), where I added an intercept column. In the data set there is a column “era” which is bundling samples belonging to the same time period together. Note: The length of the bundles varies for each era.

What I am trying to achieve is a rolling regression, where I keep the regression coeffs constant in each era but allow them to vary over the eras. Below you find the code I have so far, but am now stuck with.

```auto
features_per_era = [factors[factors.era == era].drop(columns=["era", "target"]).to_numpy() for era in factors.era.unique()]
targets_per_era = [factors[factors.era == era].target.to_numpy() for era in factors.era.unique()]

```

```auto
init_model = pm.Model()
with init_model:
  priors = list()
  for feature in ["intercept"] + features:
    sigma = pm.Exponential(f"sigma_{feature}", 50.0)
    beta = pm.GaussianRandomWalk(f"beta_{feature}", sigma=sigma, shape=len(features_per_era))
    priors.append(beta)
  betas = tt.stack(priors)

```

```auto
with init_model:
  regression = pm.math.dot(features_per_era, betas)
  sd = pm.HalfNormal("sd", sd=0.1)
  likelihood = pm.Normal("target", mu=regression, sd=sd, observed=targets_per_era)

```

There is an error in the regression calculation because features\_per\_era is a list object

```auto
TypeError: Unsupported dtype for TensorType: object

```

How can I achieve to calculate a regression with the corresponding betas per era?

Cheers
