Bookmark and Share

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


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

Re: st: a way to read directories into global


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: a way to read directories into global
Date   Tue, 13 Mar 2012 18:40:05 -0500

<>

2 suggestions:

1. you can have it detect the username (foo, in your example) with the `c(username)' stored value.  So, change your global macros to:

global dopath `"/users/`c(username)'/dropbox//"'



2.  You could have users store a starting path for their machine in their profile.do and the do-file could reference that each time Stata starts (see: http://www.stata.com/support/faqs/lang/profiledo.html) so in profile.do you could include the command:

global mystart `"/users/foo//"'
**or
global mystart `"/users/`c(username)'//"'

and that way users can specify even more divergent file paths and still use your file, e.g., 

global mystart `"/users/`c(username)'/desktop/mydocs//"

or even other OS's:

global mystart  `"C:/documents and settings/`c(username)'/mydoc//"'
	*since Windows can accept forward slashes in file paths*



then your do-file would contain this:

global dopath `"${mystart}/dropbox//"'

and each user would be responsible for establishing the $mystart macro.  Dan Blanchette's program -mkprofile- on SSC might be useful for this task.

__
An alternative would be to just specify this $mystart macro at the beginning of your do file  (instead of in the profile.do -- which might be in a restricted directory on some machines anyways) and then they could change that start of the filepath in one place at the beginning of the file and it would update the rest of the macros (if they are all written like: global dopath `"${mystart}/dropbox//"')


- Eric

__
Eric A. Booth
Public Policy Research Institute 
Texas A&M University
[email protected]
+979.845.6754

On Mar 13, 2012, at 2:31 PM, Caleb Southworth wrote:

> I am a mac user, in case the answer to this question is not generic.
> 
> I have projects that are shared among multiple authors. So that do
> files run on various machines, I have a standard set of global macros,
> such as
> 
> global dopath "/users/caleb/dropbox/p12/dofiles/"
> global datpath "/users/caleb/dropbox/p12/dta/"
> global docpath "/users/caleb/dropbox/p12/doc/"
> global tmppath "/users/caleb/dropbox/p12/tmp/"
> global origpath "/users/caleb/dropbox/p12/orig/"
> 
> Any of my collaborators can then write their own macros with the
> appropriate paths for their environment.
> 
> If the same directory and subdirectory structure existed on a
> different computer, but had a slightly different path -- say
> /users/foo/dropbox -- is there a way to have stata search for that
> information and then read it into the relevant macro?
> 
> We're already using dropbox to sync the files and avoid duplicates or
> saving over the top of one another's work.
> *
> *   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/


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