Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Phil Schumm <pschumm@uchicago.edu> |
To | statalist@hsphsun2.harvard.edu |
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:
http://www.stata.com/statalist/archive/2008-10/msg00118.htmlI 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/textmatetostata.do" 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
Data/Raw Data/Clean 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 if [ -n "$TM_PROJECT_DIRECTORY" ] then STATA_DIR="$TM_PROJECT_DIRECTORY" elif [ -n "$TM_DIRECTORY" ] then STATA_DIR="$TM_DIRECTORY" else STATA_DIR="$HOME/Desktop" fi TMPFILE="$STATA_DIR/.tm-stata-$$.do" if [ ! -e "$TMPFILE" ] then if [[ -n "$TM_SELECTED_TEXT" ]] then echo "$TM_SELECTED_TEXT" > "$TMPFILE" else echo "$TM_CURRENT_LINE" > "$TMPFILE" fi osascript <<-APPLESCRIPTtell 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}\"" APPLESCRIPT else echo "Can't create temporary file $TMPFILE (already exists)" fi * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/