Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: do file script from text wrangler

From   Phil Schumm <>
Subject   Re: st: do file script from text wrangler
Date   Mon, 23 May 2011 05:46:34 -0500

On May 22, 2011, at 8:58 PM, Eric Green wrote:

I am using TextMate on my mac, and I have the same problem with local macros described in this thread because of the temporary file issue. In my TextMate Stata bundle (i.e., program settings), I set the temp file to be created in /Code/Stata. So every time I send a selection of code to Stata, the command in Stata is preceded by:

. do "/Code/Stata/"

In my do files, I always specify the location of my data as follows:

global rawdata "/Code/Stata/Projects/[insert project name]/Data/Raw/"
global cleandata "/Code/Stata/Projects/[insert project name]/Data/ Clean"

My suggestion would be to avoid using absolute paths, since then your project is not portable. Instead, replace the paths above with


and then set your working directory to

    /Code/Stata/Projects/[insert project name]

This way, you can easily move your project to another location, another machine, etc.

WRT TextMate, below my signature is a command you can use to send the current line/selection to Stata (in TM, set Input to "None", Output to "Discard" and Save to "Nothing"). As you can see, it attempts to create the temporary file first in the project directory (if you have a TextMate project open), then in the same location as the do-file you're editing, and finally (if you haven't saved your do-file yet) on your Desktop (you can change this last location if you want). Personally, I usually have my working directory (in Stata) set to the root of my project, and then have this open in TextMate as a TM project. I also write all of my do-file code with the assumption that the working directory is the root of the project -- this way, I never have to change directories, and I always know where I am.

-- Phil

elif [ -n "$TM_DIRECTORY" ]

if [ ! -e "$TMPFILE" ]
    if [[ -n "$TM_SELECTED_TEXT" ]]
        then echo "$TM_SELECTED_TEXT" > "$TMPFILE"
        else echo "$TM_CURRENT_LINE" > "$TMPFILE"
    osascript <<-APPLESCRIPT
tell application id "com.stata.stata11" to open POSIX file "$ {TMPFILE}"
        delay 0.5  -- avoid deleting file before Stata reads it
        do shell script "rm \"${TMPFILE}\""
    echo "Can't create temporary file $TMPFILE (already exists)"

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index