Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • noob question calling Python with Stata package

    I am using STATA on a database on mac and want to translate text strings.

    I am trying to run this package https://github.com/akirawisnu/stata_translate
    I am pretty sure I installed it correctly.

    This package calls the google api to accomplish translation. However I am total noob and the package does not work = specifically I run the associated code and the package indicates it is installed by returning a message that is almost correct but it fails to generate variables with the translation - I just get the untranslated variables.

    think the problem is that I don't know how to set up python correctly, because Python is installed and accessible.

    when I run . python query in STATA I get the below message, with the giant neon blinking "no" under "initialized" that I don't know, being a noob, how to resolve. THANKS

    --
    Will

    Python Settings
    set python_exec /usr/bin/python3
    set python_userpath
    Python system information initialized no version 3.14.2 architecture 64-bit library path /Library/Frameworks/Python.framework/Versions/3.14/lib/lib
    python3.14.dylib
    Last edited by Will Hall; 31 Dec 2025, 12:12.

  • #2
    Originally posted by Will Hall View Post
    when I run . python query in STATA I get the below message, with the giant neon blinking "no" under "initialized" that I don't know, being a noob, how to resolve.
    I don't know how to fix your problem with the GitHub-sourced software package, but you can initialize Python for the Stata environment simply by typing python: and then end at Stata's command line. A subsequent python query during the same Stata session will now indicate "yes" for whether Python is initialized.

    The GitHub site indicates that you need to install two Python libraries, langdetect and deep_translator, as requirements for the GitHub site's package to work. Did you confirm that the two dependencies have been successfully installed, say, using pip show or just by trying to import them from within Stata after activating the Python environment with python:?

    Comment


    • #3
      Thank you super helpful. I was able to get a codementor guy from West Africa to walk me through it, this is the instructions and Yes a problem was the dependencies:

      **# prepare translate package for STATA (macOS)

      /*
      * confirm github installed
      net install github, from("https://haghish.github.io/github/")

      * Install my stata package (stata_translate):
      github install akirawisnu/stata_translate

      * make sure python environment working locally with miniconda Navigate to anaconda.com/download, register with Anaconda, and click Download for Mac under Miniconda Installers.

      STATA Translation Setup

      Translate text in STATA automatically - works with any language.

      QUICK SETUP

      Step 1: Install Python
      -----------------------
      1. Download Miniconda: https://docs.conda.io/en/latest/miniconda.html
      2. Install it (just click through, accept defaults)

      Step 2: Setup (One-time only)
      ------------------------------
      Open Terminal, copy-paste these commands:

      conda create -n stata17 python=3.12
      conda activate stata17
      pip install pandas deep-translator langdetect

      Step 3: Connect STATA to Python
      --------------------------------
      In Terminal:

      conda activate stata17
      /Applications/Stata/StataBE.app/Contents/MacOS/StataBE

      In STATA:

      set python_exec /opt/miniconda3/envs/stata17/bin/python
      net install github, from("https://haghish.github.io/github/")
      github install akirawisnu/stata_translate

      Done!

      Every time you open STATA:
      --------------------------
      In Terminal, run:

      conda activate stata17
      /Applications/Stata/StataBE.app/Contents/MacOS/StataBE

      In STATA:
      ---------
      stata_translate your_variable_name

      Example:

      stata_translate product_description

      This creates:
      - product_description_translated (English version)
      - product_description_srclang (original language code)

      Always open STATA from Terminal (not by clicking the icon),

      open -a Stata

      otherwise Python won't work.

      USAGE:
      stata_translate city_description food_review

      list city_description food_review

      This creates two new variables:

      *_translated
      — English translation
      *_srclang
      — Source language (e.g., 'de', 'fr', 'id')

      Comment


      • #4
        Originally posted by Will Hall View Post
        Thank you super helpful. . . . and Yes a problem was the dependencies
        You're welcome. I'm glad I could help out a bit.

        Comment

        Working...
        X