Chapter 1 Installing DDML and Python Engine
1.1 Install DDML
The main command of interest will be ddml command for double/debiased machine learning estimator. We can download the package from Stata
Another option is:
1.2 Install Python
Before we can use the Double/Debiased Machine Learning \(DDML\), we need to have at least Stata 16 and a connection to a Python engine. We need a Python engine due to the pystacked commands in the ddml commands need scikit-learn. This is a command machine learning package used in Python.
1.2.1 Step 1: Check for Python
Check to see if you have python already installed on your computer with the Stata command python search.
Python environments found:
/usr/bin/python3
/usr/local/bin/python3
/usr/local/bin/python3.7
----------------------------------------------------------------------------------
Stata returns that it found Python on my computer at “/usr/bin/python3”, but it may return “no Python installation found; minimum version required is 2.7.” if you do not have a Python engine installed.
1.2.2 Step 2: Download Python
If you do not have python, you can download Python here: https://www.python.org/downloads/
Additional information from Ahrens (2026) can be found here: https://statalasso.github.io/docs/python/
1.2.3 Another Option
You can install Anaconda with Python and connect it to Python. There is a Stata Youtube tutorial here if you prefer this option: https://www.youtube.com/watch?v=hPiFBfGpKyk.
1.3 Connect Python to Stata
After you download the Python engine, we need to integrate the Stata with the Python engine. We can use the python set exec command to connect Stata to Python
Next, run a query to check everything is set up.
Python Settings
set python_exec /usr/bin/python3
set python_userpath
Python system information
initialized no
version 3.14.3
architecture 64-bit
library path /Library/Frameworks/Python.framework/Versions/3.14/lib/
> libpython3.14.dylib
1.4 Test
Finally, we want to test that we can use Python commands in Stata.
display "Hello Python, I am Stata."
python
print("Hello Stata.")
print("I am Python.")
end
display "Nice to meet you Python!"Hello Python, I am Stata.
----------------------------------------------- python (type end to exit) --------
>>> print("Hello Stata.")
Hello Stata.
>>> print("I am Python.")
I am Python.
>>> end
----------------------------------------------------------------------------------
Nice to meet you Python!