Seeking assistance in replicating Stan model written in 2.19

I am replicating the variable duration hidden Markov model (VDHMM) introduced in the following study Naumzik, C., Feuerriegel, S., & Weinmann, M. (2022). I will survive: Predicting business failures from customer ratings. Marketing Science, 41(1), 188-207 . The entire pipeline to replicate the model presented in the paper is publicly available for download on the journal’s website in supplemental materials .

However, I encountered a problem that I tried to resolve in my earlier post on Stan forum. While I received some feedback (thanks to @WardBrian), I am still not able to fully run the model.

As far as I understand, it looks like the intent in the final iteration of the for-loop causing problems was that the line including tpm[s,s:(S-1)] should do nothing (S > S-1, so the slice s:S-1 will be empty in the final iteration). One suggestion implies trying moving that line to its own loop which ends at S-1, or wrap it in an if statement such that it does not get run in the final iteration.

Given my limited programming skills, I am seeking an expert to assist me in replicating the code. Paid collaboration is also feasible.

I think I was able to address the issue. @Moderator, please remove post.