|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: do file script from text wrangler
My solution won't work for Nirali if she wants to run sections of a
do-file instead of the entire file. The temporary do-file that the
Apple Script creates won't know about the local macros. There are
two solution:
1. Use global macros
*************************************************
global dat1 "~/Documents/Curr_Proj/project/data_1/" //path to
data_1 with "/" added to avoid typing
global dat2 "~/Documents/Curr_Proj/project/data_2/" //not used
here, but handy if you need it
use ${dat1}d1_01, clear // Note the curly brackets
(some commands)
save ${dat1}d1_02, replace
************************************************
2. Start the do-file and then change the working directory to the
data directory. This might be the easiest solution.
*************************************************
capture log close
log using p01, replace text // Start the log in the do-file directory
cd "~/Documents/Curr_Proj/project/data_1" // -cd- means "change
directory". Note there's no slash on the end.
use d1_01,clear
etc.
*************************************************
-Steve
On Oct 2, 2008, at 7:39 PM, Steven Samuels wrote:
Nirali, I think now that I understand your problem. Your data is
not in the same directory as your do-files. Now that you are
starting Stata from your do-files with the dataninja script, Stata
doesn't know where the data are. The solution is easy: in the do-
files (not the script) tell Stata where to find the data.
Here is the method I use. I create local macros to make it easy to
refer to the data sets. Suppose your data are in two different
folders, data_1 and data_2 inside a "project" folder. Create the
following macros:
*************************************************
local dat1 "~/Documents/Curr_Proj/project/data_1/" //path to
data_1
local dat2 "~/Documents/Curr_Proj/project/data_2/" //not used
here, but handy if you need it
use `dat1'd1_01, clear // use a data file in data_1
(some commands)
save `dat1'd1_02, replace // save the changes in another file
(never the same one!)
************************************************
Another possibility is to change the directory to your
To find the path to the do-files in BBEdit, I click the blue "i"
button at the top of the document; one of the options is to copy
the path to the clipboard. I'm sure that you can do the same in
Text Wrangler. Tip: keep both the do-file and log folder and the
data folders open where you can see them.
Good luck!
-Steve
On Oct 2, 2008, at 3:14 PM, Nirali Shah wrote:
Hi,
I recently downloaded the stata scripts from Dataninja. One of
these scripts allows you to send your do file straight to stata.
However, it appears that it also automatically changes the path
directory to the path directory of the do file. Since I keep my
do files and data files in different folders, every time I try and
run a do file from Text Wrangler, Stata tells me that the data
files are not found.
Aside from inserting a change directory line into each of my do
files, is there a way I can change the script? I don't know
anything about scripting language - what would I have to look for
or write?
Thank you,
Nirali
____________________________________________________
Nirali Shah
PhD Candidate, International Health, Health Systems Division
Bloomberg School of Public Health
Johns Hopkins University
*
* 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/
*
* 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/
*
* 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/