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: Working with the name of the do file


From   Michael Barker <[email protected]>
To   [email protected]
Subject   Re: st: Working with the name of the do file
Date   Thu, 2 May 2013 10:53:14 -0400

A better command for batch mode would be:

shell "C:\Program Files\Stata12\StataMP" /e do step1.do

Replace /b with /e eliminates the need to click "OK" in a pop-up window.

http://www.stata.com/support/faqs/windows/batch-mode/

On Thu, May 2, 2013 at 10:50 AM, Michael Barker
<[email protected]> wrote:
> If you are only interested in creating a log file named after the
> current do-file, you   could execute the do-file in batch mode. Batch
> mode creates a log-file named after the do-file by default. So just
> replace
>
> do step1.do
>
> with
>
> shell "C:\Program Files\Stata12\StataMP.exe" /b do step1.do
>
> replacing C:\Program Files\Stata12\StataMP.exe with the full path to
> your Stata executable.
>
> Mike
>
>
> On Wed, May 1, 2013 at 11:37 AM, Robert Picard <[email protected]> wrote:
>> I have written a program that does this (get the do-file's name from
>> within the do-file) and much more. It is called -project- and is
>> currently available from my web site by typing in Stata:
>>
>> net from http://robertpicard.com/stata
>>
>> and clicking on the -project- link. Here's the short blurb from the
>> description page:
>>
>> project automates the execution of do-files, skipping unchanged
>> do-files with unchanged dependencies (files used and created by
>> each do-file). All do-files are logged automatically. Stata's
>> current working directory is dynamically changed to match the
>> directory of the current do-file. Files in the do-file's
>> directory can always be accessed by file name while files
>> elsewhere can be accessed using a file path that is relative to
>> the project's main directory. Since full path names are not used,
>> the whole project directory can be moved or shared with someone
>> else without having to edit any file paths.
>>
>> project can verify replication by comparing all files created by
>> the project (data, tables, graphs, log files, etc.) against
>> those produced by a replication run. Project files can be listed
>> in various ways, backed up, and shared with others. project can
>> also clean up the project directory by moving any file not linked
>> to the project to an archive directory.
>>
>> A toy project that runs some examples from the version 12 Stata
>> reference manuals is included in the ancillary files below.
>> A reduced version that runs with Stata 9 is also included.
>>
>> On Tue, Apr 30, 2013 at 6:20 PM, Eric DeRosia <[email protected]> wrote:
>>> I want to make my Stata do files easier to use and maintain.  Is there a way
>>> to access the name of the do file from within the do file itself, perhaps as
>>> a macro or a system variable?  Let me give an example of what I mean.  I
>>> have a do file such as the following:
>>>
>>> filename: step1.do
>>> -------------------
>>>    /// some Stata code here
>>> log using "step1.log", replace
>>>    /// more Stata code here
>>> display "Output from step1.do"
>>>    /// more Stata code here
>>> graph export "step1.emf", replace as(emf)
>>>
>>>
>>> In this example, if I want to re-use the code by copying the file and
>>> creating "step 2.do", my current workflow process is to edit the file and
>>> replace all the instances of "step1" in the file with "step2". Beyond the
>>> obvious inconvenience of editing the file every time I re-use the code, I
>>> occasionally forget to make the change, so running step2.do accidentally
>>> overwrites step1.log, etc.  I'm looking for a better way.
>>>
>>> I think something like the following would solve my problem.  Is there a way
>>> to accomplish this in Stata?
>>>
>>>
>>> filename: step1.do
>>> -------------------
>>>    /// some Stata code here
>>> log using "`_name_of_the_do_file'.log", replace
>>>    /// more Stata code here
>>> display "Output from `_name_of_the_do_file'.do"
>>>    /// more Stata code here
>>> graph export "`_name_of_the_do_file'.emf", replace as(emf)
>>>
>>> In the code above, I made up "`_name_of_the_do_file'" out of thin air to
>>> illustrate what I would like to do.  My hope is to find a string that
>>> resolves to "step1.do" based on the filename.  (In this example, I didn't
>>> deal with the fact that ".do" that would be at the end of the string, but
>>> it's clear to me how I would deal with that once I had access to the
>>> filename.)  Is there any way for Stata to get access to the name of the do
>>> file?
>>>
>>> In case it matters, I'm using Stata 12 in a Windows environment.
>>>
>>> Thank you in advance for any help you can offer on this!
>>>
>>> - Eric
>>>
>>> --
>>> Eric DeRosia, Ph.D.
>>> Assistant Professor
>>> Business Management
>>> Marriott School of Management
>>> Brigham Young University
>>> 671 TNRB
>>> Provo, Utah 84602
>>>
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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