Hierarchical Model: Chains do not mix when I include controls

Hi all,

I am new on the discourse and relatively new at STAN, but a big fan. I have a problem with a hierarchical time series model. I am rebuilding a fixed effect linear panel regression because I want more insight to the uncertainty in parameters.

When I include only the variables that turned out highly significant (t-test rejects at 1 % level) the model runs smoothly and gives the same results as the frequentist version, as expected. However, when I include controls that are found to be insignificant in the PL, the model takes substantially longer to compute, and an inspection of the traceplots indicates that the chains do not mix for any of the variables.

I already tried increasing adapt_delta and max_treedepth. I also reparametrized the Cauchy priors and the normal posterior as proposed in the STAN manual.

The variables that turn out insignificant are “kl”, “go” and “pg”.

I am grateful for any help.

data {
  int<lower=1> N; // number of observations
  int<lower=1> J; // number of industries
  int<lower=1> T; //number of periods
  int<lower=1,upper=J> industry[N];
  int<lower=1,upper=T> year[N];
  vector[N] x; //RKT
  vector[N] y; //IFTC
  vector[N-J] y2; //IFTC for all but first period
  vector[N] kl;
  vector[N] go;
  vector[N] pg;
}
parameters {
  vector[J] alpha; // intercept
  vector[4] beta; // slope
  vector[2] gamma;
  real mu_alpha;
  real mu_beta;
  real mu_gamma;
  real<lower=0> sigma; //variance of observation
  real<lower=0> sigma_alpha; //variance of intercept
  real<lower=0> sigma_beta; //variance of slope
  real<lower=0> sigma_gamma;
}
model {
  vector[N - J] y_hat; // predictions 
  int pos; //position in raw dataset
  int local_pos; //continuous index for y_hat only
  pos = 0;
  local_pos = 0;
  
  for(j in 1:J){
    for(t in 2:T){
      local_pos = local_pos + 1;
      pos = (j-1)*T + t; //number of time periods per group + current time period 
      y_hat[local_pos] = alpha[industry[pos]] + y[pos-1] * gamma[1] + x[pos-1] * gamma[2] + x[pos] * beta[1] + kl[pos] * beta[2] + pg[pos] * beta[4];
    }
  }
  
  alpha ~ normal(mu_alpha, sigma_alpha);
  beta ~ normal(mu_beta, sigma_beta);
  gamma ~ normal(mu_gamma, sigma_gamma);
  sigma ~ cauchy(0, 2.5);
  mu_alpha ~ normal(0, 1);
  sigma_alpha ~ cauchy(0, 2.5);
  mu_beta ~ normal(0, 0.3);
  sigma_beta ~ cauchy(0, 0.5);
  mu_gamma ~ normal(0, 0.3);
  sigma_gamma ~ cauchy(0, 0.5);
  
  y2 ~ normal(y_hat, sigma);
}

Quick edit: I changed the forward ticks to back ticks so it shows as a code block.

thank you, I wont make the same mistake again