# ";" expected after variable declaration

**URL:** <https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571>\
**Category:** Modeling\
**Created:** [March 22, 2024, 7:58pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571 "2024-03-22T19:58:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad.stone](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@brad.stone](https://discourse.mc-stan.org/u/brad.stone)\
**Post date:** [March 22, 2024, 7:58pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/1 "2024-03-22T19:58:37Z")

</div>

I having been running in circles with this same issues for hours today, to no avail. Forums have not led me anywhere in terms of getting closer to resolving (what should be) a very simple issue (see stan below). I am getting the “;” expected after variable declaration (referenced to y[N]; on line 4). I have tried everything from reinstalling mingw32 and cmdstan, to creating different stans w/o the y[N] line. The latter does work, but y[N] should work, as I have seen them applied in several examples online. If I trying having minwg32 make the stan (as a forum suggested) I get the same error, along with an error that says:

‘cut’ is not recognized as an internal or external command,  
operable program or batch file.  
‘cut’ is not recognized as an internal or external command,  
operable program or batch file.  
process\_begin: CreateProcess(NULL, expr \>= 8, …) failed.  
The system cannot find the file specified.  
stan/lib/stan\_math/make/compiler\_flags:174: make/ucrt: No such file or directory  
INFO: Could not find files for the given pattern(s).  
‘’  
‘— Translating Stan model to C++ code —’

I am super frustrated and hoping someone knows what I have done wrong and how (whether) I can fix this? Thanks.

* * *

```stan
data {
  int<lower=0> N; // Number of observations
  int<lower=1> K; // Number of categories in the outcome variable
  int<lower=1, upper=K> y[N]; // Altitude sickness category for each observation
  matrix[N, 4] X; // Predictor matrix: elevation, oxy_sat, HRV, acclimatization
}
parameters {
  matrix[4, K-1] beta; // Coefficients for predictors (K-1 because one category is a baseline)
}
model {
  // Assuming a standard normal prior for simplicity
  for (j in 1:(K-1)) {
    beta[:, j] ~ normal(0, 5);
  }
  // Multinomial logistic regression
  y ~ categorical_logit(X * beta);
}

```

* * *

---

<div class="post-metadata">

**Author:** ![Haoran\_Matt\_Wan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/haoran_matt_wan/32/12307_2.png) [@Haoran\_Matt\_Wan](https://discourse.mc-stan.org/u/Haoran_Matt_Wan)\
**Post date:** [March 22, 2024, 8:00pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/2 "2024-03-22T20:00:53Z")

</div>

I encountered the same problem yesterday. For your `int<lower=1, upper=K> y[N];` in the data block, the latest syntax should be `array[N] int<lower=1, upper=K> y`.

---

<div class="post-metadata">

**Author:** ![brad.stone](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@brad.stone](https://discourse.mc-stan.org/u/brad.stone)\
**Post date:** [March 22, 2024, 8:12pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/3 "2024-03-22T20:12:30Z")

</div>

You are a true godsend! It worked. I could not find a solution to this ANYWHERE. Thanks a ton.

---

<div class="post-metadata">

**Author:** ![Ven\_Popov](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ven_popov/32/15885_2.png) [@Ven\_Popov](https://discourse.mc-stan.org/u/Ven_Popov)\
**Post date:** [March 22, 2024, 8:43pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/4 "2024-03-22T20:43:55Z")

</div>

a search of the forums for this error message brings a few recent topics with this issue and the above solution:

[https://discourse.mc-stan.org/search?q=%22%3B%22%20expected%20after%20variable%20declaration%20order%3Alatest](https://discourse.mc-stan.org/search?q=%22%3B%22%20expected%20after%20variable%20declaration%20order%3Alatest)

- [Parser expected when defining data](https://discourse.mc-stan.org/t/parser-expected-when-defining-data/34483)
- [Stuck with Stan compiling with cmdstanr - #3 by AB25](https://discourse.mc-stan.org/t/stuck-with-stan-compiling-with-cmdstanr/34218/3)
- [Parsing error with random effect in brms](https://discourse.mc-stan.org/t/parsing-error-with-random-effect-in-brms/34063)

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [March 23, 2024, 3:09pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/5 "2024-03-23T15:09:45Z")

</div>

> [@brad.stone](#):
>
> I could not find a solution to this ANYWHERE

where did you look first?

is it possible to update the RStan docs without having to do a whole new CRAN release?

---

<div class="post-metadata">

**Author:** ![Ven\_Popov](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ven_popov/32/15885_2.png) [@Ven\_Popov](https://discourse.mc-stan.org/u/Ven_Popov)\
**Post date:** [March 23, 2024, 3:22pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/6 "2024-03-23T15:22:40Z")

</div>

@mitzimorris maybe it’s worth temporarily pinning a topic (or this post?) in the forums with the title of the error since it keeps comming up and it might make it easier for people to find.

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [March 23, 2024, 3:37pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/7 "2024-03-23T15:37:33Z")

</div>

Pinned globally on March 23, 2024, 3:37pm UTC



---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [March 23, 2024, 4:03pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/8 "2024-03-23T16:03:21Z")

</div>

> [@mitzimorris](#):
>
> is it possible to update the RStan docs without having to do a whole new CRAN release?

This has to have been CmdStanR

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [March 24, 2024, 11:42am UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/9 "2024-03-24T11:42:12Z")

</div>

How about adding to sections “[Data Types and Declarations](https://mc-stan.org/docs/reference-manual/types.html#scalar-data-types-and-variable-declarations)” and “[Data Types and Declarations](https://mc-stan.org/docs/reference-manual/types.html#array-data-types.section)” something like

> Stan version before x.yy allowed declaring arrays of integers as `int N<size>;`. This is not supported since Stan version x.yy. See Array data types for the current syntax.

And maybe add in the end of page “[Data Types and Declarations](https://mc-stan.org/docs/reference-manual/types.html)” a subsection “Compiler error messages” with something like

> ### Compiler syntax error messages
> 
> `";" or plain assignment expected after variable declaration.`
> 
> - the code is missing `;` or
> - the code is using the old array syntax, see the current syntax in Section “Array data types” [Data Types and Declarations](https://mc-stan.org/docs/reference-manual/types.html#array-data-types.section)

Maybe then eventually search for this syntax error will point to the Stan manual. There will be code examples with old syntax for many years.

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [March 25, 2024, 5:57pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/10 "2024-03-25T17:57:00Z")

</div>

The next release will feature an improved message in this case

---

<div class="post-metadata">

**Author:** ![npretnar](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@npretnar](https://discourse.mc-stan.org/u/npretnar)\
**Post date:** [April 10, 2024, 3:02am UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/11 "2024-04-10T03:02:16Z")

</div>

I’m running into the same error, though it does not involve an mis-specified integer array (at least I do not think it does). Any help is greatly appreciated. Th error is:

## Compiling Stan program… Syntax error in ‘/var/folders/m7/zgrjwxmj76vcyj3w0shwp5p00000gn/T/Rtmp7upG1r/model-5bd433ab8474.stan’, line 23, column 15 to column 16, parsing error:

```
21: vector<lower=0>[J] varphi_int;
22: array[T] vector[J] varphi;
23: vector<lower=0>[J] nxi;
                    ^
24:  

```

## } 25:

“;” expected after variable declaration.

make: \*\*\* [/var/folders/m7/zgrjwxmj76vcyj3w0shwp5p00000gn/T/Rtmp7upG1r/model-5bd433ab8474.hpp] Error 1

Error: An error occured during compilation! See the message above for more information.

> 

```no-highlight

// DATA BLOCK
data {

int<lower=1> H;
int<lower=1> J;
int<lower=1> T;
int<lower=0> T0;
vector[J] ln_lq[H];
vector[J] lw_lP[H];
row_vector[H] weight;
array[H] int<lower=1,upper=T> year;

// hyperparameters
vector[J] mu_xi;
vector[J] sigma_xi;

}

// PARAMETER DECLARATIONS
parameters {

cholesky_factor_corr[J] L_Omega;
vector<lower=0>[J] L_sigma;
vector<lower=0>[J] varphi_int;
array[T] vector[J] varphi;
vector<lower=0>[J] nxi;

}

// TRANSFORMED PARAMETERS
transformed parameters {

vector[J] fe_int[T];
vector[J] ln_lq_hat[H];	
matrix[J,J] L_Sigma;
vector[J] phi;

phi = 1 ./ (-nxi - 1);

L_Sigma = diag_pre_multiply(L_sigma, L_Omega);

for(t in 1:T){
fe_int[t] = varphi_int .* varphi[t];
}

for(h in 1:H){
ln_lq_hat[h] = lw_lP[h] .* phi + fe_int[year[h]];
}

}

// MODEL BLOCK
model {

// - xi
nxi ~ lognormal(mu_xi,sigma_xi);

// Var/Covar Objects
L_Omega ~ lkj_corr_cholesky(4);
L_sigma ~ cauchy(0, 2.5);

// Fixed effect terms
for(t in 1:T){
varphi[t] ~ normal(0,1);
}

for(h in 1:H){
target += multi_normal_cholesky_lpdf(ln_lq[h] | ln_lq_hat[h], L_Sigma) .* weight[h];
}

}

// GENERATED QUANTITIES BLOCK
generated quantities{

vector[J] xi;
vector[J] alpha;
array[T0,J] real year_fe; 
array[H,J] real zeta;

xi = - nxi;
alpha = exp((phi-1) .* fe_int[1]) ./ (1+exp((phi-1) .* fe_int[1]));

// Fixed effects less reduced form intercept common to all years
for(t in 2:T){
year_fe[t-1] = fe_int[t] - fe_int[1];
}

// Productivities by agent, including common, fixed-effect components
for(h in 1:H){
zeta[h] = exp(- (ln_lq_hat[h] - lw_lP[h] .* phi - fe_int[1]) .* phi .* xi);
}

}

```

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [April 10, 2024, 3:54pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/12 "2024-04-10T15:54:22Z")

</div>

> [@npretnar](#):
>
> ```no-highlight
> vector[J] ln_lq[H];
> vector[J] lw_lP[H];
> 
> ```

These lines in your data block seem to be the issue - they’re also using the removed array syntax and need to be `array[H] vector...` instead. I get a different error message than you that points me to these lines when I try to compile your model

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [June 17, 2024, 1:27pm UTC](https://discourse.mc-stan.org/t/expected-after-variable-declaration/34571/13 "2024-06-17T13:27:50Z")

</div>

Unpinned on June 17, 2024, 1:27pm UTC


