Proxy settings in Stata


Recently, I bring my laptop to work instead of using the desktop provided for me. Because access to the network requires specific proxy settings, I manually enable/disable/change proxy settings in Stata and Internet Explorer. Instead of going through this point-and-click process to change proxy settings twice a day, I figured that I can just create two do-files—one to enable, the other to disable proxy settings, in both Stata and Internet Explorer!

When I get into the office, I will run enable.do:


*****enable.do
*****ENABLE PROXY: STATA*****

set httpproxy on
set httpproxyhost “proxy2.xxxx.org”    // xxxx is not the actual entry
set httpproxyport 8080

*****ENABLE PROXY: INTERNET EXPLORER*****
*****Source: How do I Change the Internet Explorer Proxy Settings From a Command Prompt?

shell reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 1 /f

shell reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyServer /t REG_SZ /d proxy2.xxxx.org:8080 /f    // xxxx is not the actual entry


And when I get home, I will run disable.do:


*****disable.do
*****DISABLE PROXY: STATA****
set httpproxy off

*****DISABLE PROXY: INTERNET EXPLORER*****
*****Source: How do I Change the Internet Explorer Proxy Settings From a Command Prompt?

shell reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 0 /f


This seems trivial, but, to me it means minus 2 annoying tasks everyday. I am still looking for a way to do the same for the Firefox browser.

4 Responses

  1. Mitch saves the day! :)

  2. […] Proxy settings in Stata […]

  3. Rather than having to run these .do files each time you run/restart Stata, you could put some commands in your profile.do to deal with these settings.

    Here’s 3 ideas (watch for wrapping issues below) :

    //1. You could put a script in the profile that asks you each time you launch Stata about whether you’d like to connect to your proxy – you can click yes or no:

    *****************
    cap window stopbox rusure “CONNECT TO PROXY??”
    if _rc == 0 {
    set httpproxy on
    set httpproxyhost “proxy2.xxxx.org” // xxxx is not the actual entry
    set httpproxyport 8080
    shell reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 1 /f
    shell reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyServer /t REG_SZ /d proxy2.xxxx.org:8080 /f // xxxx is not the actual entry
    }
    else {
    set httpproxy off
    shell reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 0 /f
    }
    *****************

    //2. If you were using one platform (say, Windows) at the office and another at work (say, MacOSX), you could have Stata detect the platform and change the proxy settings accordingly.

    *****************

    if “`c(os)'” == “MacOSX” {

    }
    if “`c(os)'” == “Windows” {

    }
    *****************

    //3. Finally, I’ve been toying with something that detects your location (based on your IP address) and changes settings (for me it’s about connecting to SMB drives if I’m in certain locations) — I’m haven’t tried this with Windows yet but the shell command is similar to the “ifconfig” line below (probably something like: ” shell ipconfig >> myfile.txt ” )
    So, the code below copies the ipaddress to the “ip.txt” file, uses Stata to split out the ip address to pull the parts that let me know that I’m on my home, campus office, or other wireless network and then changes my settings appropriately. If you test
    *****************
    **mac os only – change location / ip**
    cap erase “/users/ppri/desktop/ip.txt”
    ! ifconfig en1 | grep “inet 19” > “~/desktop/ip.txt”
    preserve
    clear
    insheet using “/users/ppri/desktop/ip.txt”, nonames
    drop v1
    split v2, p(” “)
    keep v22
    split v22, p(“.”)

    **real address components substituted for “x” below**
    if v222 == “1xx” & v223== “2xx” {

    loc marker 1
    }

    if v222 == “1xx” & v223 == “15x” {

    loc marker 1
    }

    if loc marker != 1 {

    }
    restore
    *****************

    – Eric
    eric.a.booth@gmail.com

Leave a Reply