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: Creating automatic log file when I start Stata in MAC


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: Creating automatic log file when I start Stata in MAC
Date   Thu, 2 Dec 2010 22:41:38 +0000

<>

I'd start by changing your filepath from "/documents/statalogs/" to "/users/<youruser>/documents/statalogs/" (unless you've moved "documents") and confirming that the directory exists.  You can use `c(username)' instead of your username if you are putting this in the profile of multiple machines.

At one point in time, I tried to get -window control- to allow me to prompt for information, but never got it to work.  Instead, try using the "request()" option of -display- to prompt you.


Using the "request()" option plus a couple of other changes, you could simplify all this code to something like this (unless you're stuck on working with -window control-):
***********!
cap program drop setlogfile
program define setlogfile

version 10

**define timestamp**
local time:display  %td  date("$S_DATE", "DMY") "_" substr("$S_TIME",1,2) "-" substr("$S_TIME",4,2)

**request logfilename**
noi di " ENTER LOGFILE NAME --> "  _request(answer)
if "${answer}" == ""  {
	global answer  log   // Default prefix to your logfiles if you just hit Return
}


**define statalogs location:
global ldirectory "/users/`c(username)'/documents/statalogs//"

cap mkdir "${ldirectory}"
global lfile "${ldirectory}/${answer}_`time'.log"

**start log file**
cap log close _all
log using "${lfile}", append
	di as smcl "Log File {bf:${answer}} saved in folder: {browse $ldirectory}"
end


****************************************
**Run or include in your profile.do -->
**setlogfile
***********!
You can make the $ldirectory OS specific if you are running this on various machines with different platforms; something like:

if "`c(os)'" == "MacOSX"  global ldirectory "/users/`c(username)'/documents/statalogs//"
if "`c(os)'" == "Windows" global ldirectory  "C:/statalogs//"
**note: I used forward slashes in the Windows path based on advice here:  http://www.stata.com/statalist/archive/2009-05/msg00262.html


- Eric

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



On Dec 2, 2010, at 3:44 PM, Donald Spady wrote:

> I am trying to modify a program called set_log_file.ado to put into my profile.do so as to prompt me to enter a filename for a logfile.  I am doing this for Stata 11 in MAC OS (snow leopard) 
> When I try what is written below, it does not prompt me for a file name and just goes on to the end and then says "file/documents/statlogs/.log could not be opened.
> It is not my program, but I got it from somewhere many years ago and it worked OK on a PC.  Now I have a MAC and am having some teething problems.
> 
> The program is as follows
> 
> macro drop DB*
> capture program drop set_log_file
> program define set_log_file
>  version 7.0
> 
> local x : display %dNDY date("$S_DATE","dmy") substr("$S_TIME",1,2) substr("$S_TIME",4,2)
> global DB_filename "Enter log file name:"
> *window control static DB_filename 10 10 100 10
> *window control edit 10 20 175 8 DB_fname
> *window control button "OK" 10 40 50 10 DB_ok default
> *window control button "Cancel" 70 40 50 10 DB_can escape
> global DB_ok "exit 3001"
> global DB_can "exit 3000"
> 
> * change the 400 400 co-ordinates below to centre the dialog box on your own screen
> * if you want smcl output, just drop the +."log" part below
> * and change "basic.log" to "basic" (or any other name that suits)
> * capture noisily window dialog "Log file details"  400 400 200 70
> if _rc==3001 {
>  global DB_fname="$DB_fname.log"
>  }
>  else
> if _rc==3000 {
>    global DB_fname="basic.log"
>  }
> *add your own path statements on the following line
> global lfile="/documents/statalogs/"+"$DB_fname"
> log using $lfile, append
> *log using $DB_fname
> end
> 
> The *window lines are commented out because the use of the word 'control' for some reason doesn't work
> 
> Where am I going wrong.
> 
> Many thanks
> 
> Don Spady
> 
> Nature bats last.
> 
> 
> *
> *   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