Future of using Stan from Stata

Since version 16, Stata has featured close integration with Python, so you can type Python code inside your Stata script, and pass objects back and forth.

I wrote StataStan in 2014-15 and it is one of those make-do interfaces that are just wrappers for CmdStan. It relies on passing data, model, chains etc via text files, and that has always been a weakness, producing occasional problems dependent on users’ OSs, security settings and so on.

My view now is that anyone who wants to use Stan from Stata should do so through PyStan or CmdStanPy. In interface terms, the speed and stability will be better than the -stan- command. I intend to freeze StataStan for Stata versions pre-16 but not to maintain compatibility going forward.

I am posting this on Statalist and the GitHub page too. Please let me know if you have any contrary views. Best use my email robert@bayescamp.com

8 Likes

Thanks Robert, that makes sense to me.

Last week I pushed a new StataStan 1.2.4 which just displays a warning message if you are using Stata version ≥16. It advises you to consider using PyStan or CmdStanPy vis Stata’s Python integration. You can turn off the warning with the new “nopywarn” option. The warning is also in the Stata help file. This version 1.2.4 is also on the Stata repository of community-contributed commands SSC. Thanks to William Lisowski for the suggestion, to catch people who update but don’t read all the docs (which is basically everybody).

2 Likes

Robert:

Would you be interested in writing a brief tutorial / case study on how to use Stan in Stata via python? I’m guessing CmdStanPy would be the best route, but I’m not sure. We could then put this on the web. Without a case study I fear that users will be running around the web like chickens with their heads cut off, trying to figure out exactly what to do!

1 Like

I think you’re right. I’ll see what I can do.
@breckbaldwin maybe could you let me know offline how best to format it so it fits nicely into the case studies?

Thanks! Once it exists (or if you need help before that), just let me know.