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
Donald Spady <[email protected]>
To
[email protected]
Subject
Re: st: Creating automatic log file when I start Stata in MAC
Date
Thu, 2 Dec 2010 21:19:32 -0700
Eric
I rewrote my program using the commands you entered below. Immediately below this sentence is my program, annotated as to where it didn't work. As you can see, it does work a bit, but
the date function does not work, and the whole program does not work, but part of it does.
macro drop DB*
capture program drop setlogfile
program define setlogfile
version 10.0
**define timestamp**
local time:display %td date("$S_DATE","DMY")"_"substr("$S_TIME",1,2)"-"substr("$S_TIME",4,2)
//This returns an unknown function () message//
**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/DonSpady/documents/statalogs//"
//This returns ENTER LOGFILE NAME:.
//which doesn't work because the '.' is there and when I put in a file name in the command box
// so I enter the logfile name test
// and it echoes: ENTER LOGFILE NAME:. test
cap mkdir "${ldirectory}"
*global lfile "${ldirectory}/${answer}_'time'.log"
//I commented this command out because of the unknown function() message with the date stamp definition.
global lfile "${ldirectory}/${answer}.log"
** start logfile **
cap log close _all
log using "${lfile}", append
di as log "Log File {bf:${answer}} saved in folder: {browse $ldirectory}"
end
// IF I run just from noi di ... on to end I get the prompt and I enter a file name and then I get an
//'invalid syntax' r(198)
// return, BUT the file is opened in the directory and it starts to log it all.
// IF I save the whole file and put it in my profile.do command, all I get is the other profile commands I have
//entered, like set mem 10 m and so on. NO PROMPTS, NO LOG FILE.
// SOMETHING is working, but not all of it.
Where am I going wrong.
Many thanks for all your help so far.
Don
On 2010-12-02, at 3:41 PM, Eric Booth wrote:
> <>
>
> 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/
>
Don Spady
Ring the bell that still can ring
*
* 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/