Announcement

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

  • New environment variables not recognized by Stata

    Dear Statalist,

    I am using Stata 15 (on a mac with OS High Sierra). I created a new environment variable (let's call it "data") using the .bash_profile file. I am now trying to have Stata recognize it, but it does not work. Two findings that make the problem puzzling to me:

    1. The new variable seems to be correctly recognized by my computer. If I write in the terminal:
    echo $data
    it returns the right value.

    2. I can access env variables that are native from my computer in Stata. For example,
    Code:
    global home: env HOME
    di "$HOME"
    returns the right value.



    However,
    Code:
    global data: env data
    di "$data"
    returns blank

    Any insights on why this could happen?
    Thanks,
    Andrés

  • #2
    I'm running the same setup as you, but my login shell is tsh with initialization done by the .tshrc file. When from within Stata I run
    Code:
    shell setenv
    I see all my environment variables, including the ones I set in my .tshrc file. What do you see when you do the equivalent bash command to display environment variables? And if it doesn't show your "data" environment variable, did you export it after defining it?

    Comment


    • #3
      .bash_profile is read at login, upon new terminal launch, or if you manually source the file; so you will need to satisfy one of those 3 requirements. Personally, I would launch a terminal, make the additions/modifications to .bash_profile and then:

      Code:
      source ~/.bash_profile
      Once the new variables have been imported, you can then launch a new Stata session:

      Code:
      /Applications/Stata15/Stata.app/Contents/MacOs/Stata &
      and your variables should be available.

      -Pete

      Comment


      • #4
        Hi guys,
        Thanks for your answers. I tried to do what Pete had suggested, but the variables were only available when using Stata in the same session of Terminal, not when opening it directly. After some more tinkering, I came up with a solution in Stackoverflow (here). The problem was on how to create environment variables for them to be globally available in any application, not specifically related to Stata.

        In case someone has the same problem, this is what I am doing now:

        Launch AppleScript Editor, enter a command like this:
        do shell script "launchctl setenv variablename value"
        (add as many lines as you like)
        Now save (⌘S) as File format: Application.
        Finally open System Settings → Users & Groups → Login Items and add your new application.

        I hope this can be useful for more people.
        Best,
        Andrés


        Comment

        Working...
        X