'Identifier expected after type in top-level variable declaration.'

When I run the following program I get the error: ‘‘Identifier expected after type in top-level variable declaration.’’. This error occurs when I have added the loop in the model and generated the quantities statement. Does somebody know what this exactly means? I do not know which variable is giving the error.

functions {
   real[] model3(real t, real[] y, real[] theta,
  real[] x_r, int[] x_i){
    
    real AB= y[1];
    real ASC = y[2];
    
    real pAB = theta[1];
    real uAB = theta[1]; 
    real uASC = theta[3];
    
    real dydt[2];
    
    dydt[1] = pAB*ASC - uAB*AB;
    dydt[2] = -uASC*ASC;
    
   return dydt;
    
  }
}

data{
  int <lower=0> nobs;
  real t0;
  real y0[2];
  real ts[nobs];
  int <lower=1> indivs;
  real antib[nobs];
  //real <lower=1, upper=indivs> subj[nobs];
}

transformed data{
  real x_r[0];
  int x_i[0];
}

parameters{
  //real <lower=0> AB0;
  real <lower=0> pAB;
  real <lower=0> uAB;
  real <lower=0> uASC;
  //real <lower=0> z_init[2];
  //real <lower=0> sigmaAB0;
  real <lower=0> sigma;
}

transformed parameters{
  real yhat[nobs,2];
  {
    real theta[3];
    theta[1] = pAB;
    theta[2] = uAB;
    theta[3] = uASC;
    
    yhat = integrate_ode_bdf(model3, y0, t0, ts, theta, x_r, x_i);
  }
}

model{
  
  pAB ~ lognormal(-2, sqrt(4));
  uAB ~ lognormal(-1, sqrt(2));
  uASC ~ lognormal(-0.1, 0.44);
  //AB0 ~ lognormal(-2, 4);
  //sigmaAB0 ~ gamma(0.001, 0.001);
  //z_init ~ lognormal(5,1);
  sigma ~ normal(0, 1);
  
  for (i in 1:nobs){
    antib[i] ~ lognormal(yhat[i,1], sigma);
  }

}

generated quantities{
  real[nobs] z_pred;
  for (j in 1:nobs){
    z_pred[j] = lognormal_rng(yhat[j,1], sigma); 
  }
}
****
Thanks in advance.

CmdStan points to the problematic variable:

Syntax error in 'identifier.stan', line 76, column 6 to column 7, parsing error:
   -------------------------------------------------
    74:  
    75:  generated quantities{
    76:    real[nobs] z_pred;
               ^
    77:    for (j in 1:nobs){
    78:      z_pred[j] = lognormal_rng(yhat[j,1], sigma); 
   -------------------------------------------------

Identifier expected after type in top-level variable declaration.

Unlike vector dimension, array dimension goes after the variable name

generated quantities {
  real z_pred[nobs];

or if you’re using the new syntax, before the type name

generated quantities {
  array[nobs] real z_pred;

Thanks! I no longer have that error. But if I modify this as r zpred[nobs], I get the following error message:

rstan:::rstudio_stanc(“R/Rstan/expdecay2.stan”)
Error in stanc(filename, allow_undefined = TRUE) : 0

Syntax error in ‘string’, line 57, column 13 to column 14, parsing error:

Expected end of file after end of generated quantities block.’

Line 57 doesn’t make sense for the model but “expected end of file” sounds like you have something after the last }, or maybe too many } somewhere before, or a missing {.

Thanks! That worked