1

I'd like to run a jupyter notebook that can run multiple languages (one in each column) to show how to run simple things in each respective languages (r, python, stata). Is there such extension to do so?

wowzaaa
  • 141
  • 2
  • 12

1 Answers1

3

To use R and Stata code alongside your Python code in the same Jupyter notebook, you need to install IPYStata for Stata and rpy2 for R.

Install IPYStata with pip install ipystata and use it with the %%stata magic:

In[1]: import ipystata  
In[2]: %%stata  
display "Hello, I am printed in Stata."  

Install rpy2 with pip install rpy2 and import robjects:

import rpy2.robjects as robjects
pi = robjects.r['pi']
pi[0]

Check the documentation and see this answer for more details

Alternatively, if you want to run Stata code in separate Jupyter notebooks, you can use stata_kernel

J-B
  • 493
  • 2
  • 7