Transcription of Saving and printing output—log files
1 15 Saving and printing output log and closing to an existing and resuming comments in only what you log-button multiple log files for simultaneous OverviewStata can record your session into a file called a log file but does not start a log automatically; youmust tell Stata to record your session. By default, the resulting log file contains what you type and whatStata produces in response, recorded in a format called Stata Markup and Control Language (SMCL);see [P]smcl. The file can be printed or converted to plain text for incorporation into documents youcreate with your word start a log:. log usingfilenameYour session is now being recordedin temporarily stop logging:Temporarily stop:. log offResume:. log onTo stop logging and close the file:. log closeYou can now type:. you canload into your word can also create a PDF Windows or Mac:. ways to start logging:append to an existing log:. log usingfilename, appendreplace an existing log.
2 Log usingfilename, replaceUsing the GUI:To start a log:click on theLogbuttonTo temporarily stop logging:click on theLogbutton, and chooseSuspendTo resume:click on theLogbutton, and chooseResumeTo stop logging and close the file:click on theLogbutton, and chooseCloseTo print previous or current log:selectFile > , choose file,right-click on the Viewer, and selectPrintAlso,cmdlogwill produce logs containing solely what you typed logs that, although not containingyour results, are sufficient to re-create the start a command-only log:. cmdlog usingfilenameTo stop logging and close the file:. cmdlog closeTo re-create your session:. [ U ] 15 Saving and printing output log Starting and closing logsWith great foresight, you begin working in Stata and typelog using session(or click on theLogbutton) before starting your work:. log using sessionname: <unnamed>log: C:\example\ type: smclopened on: 17 Mar 2013, 12:35:08.
3 Use (1980 Census data by state). tabulate region [freq=pop]CensusregionFreq. Percent ,135,283 Cntrl58,865,670 ,734,029 ,172,490 ,907,472 summarize median_ageVariableObs Mean Std. Dev. Min Maxmedian_age50 log closename: <unnamed>log: C:\example\ type: smclclosed on: 17 Mar 2013, 12:35:38 There is now a file your disk. If you were to look at it in a text editor orword processor, you would see something like this:{smcl}{com}{sf}{ul off}{txt}{.-}name: {res}<unnamed>{txt}log: {res}C:\example\ {txt}log type: {res}smcl{txt}opened on: {res}17 Mar 2013, 12:35:08{com}. use {txt}(1980 Census data by state){com}. tabulate region [freq=pop]{txt}Census {c |}region {c |} Freq. Percent Cum.{hline 12}{c +}{hline 35}NE {c |}{res} 49,135,283 {txt} N Cntrl {c |}{res} 58,865,670 (output omitted)What you are seeing isSMCL, which Stata understands.
4 Here is the result of typing the file usingStata stypecommand:[ U ] 15 Saving and printing output log files 3. type : <unnamed>log: C:\example\ type: smclopened on: 17 Mar 2013, 12:35:08. use (1980 Census data by state). tabulate region [freq=pop]CensusregionFreq. Percent ,135,283 Cntrl58,865,670 ,734,029 ,172,490 ,907,472 summarize median_ageVariableObs Mean Std. Dev. Min Maxmedian_age50 log closename: <unnamed>log: C:\example\ type: smclclosed on: 17 Mar 2013, 12:35 you will see is a perfect copy of what you previously saw. If you use Stata to print the file,you will get a perfect printed copy, can be translated to plain text, which is a format more useful for inclusion into aword processing document. If you , Stata will text and store the result :. translate resulting like this:----------------------------------- ---------------------------------------- ----name: <unnamed>log: C:\example\ type: smclopened on: 17 Mar 2013, 12:35:08.
5 Use (1980 Census data by state). tabulate region [freq=pop]Census |region | Freq. Percent +-----------------------------------NE | 49,135,283 Cntrl | 58,865,670 | 74,734,029 (output omitted)When you usetranslateto , notalready exist:4 [ U ] 15 Saving and printing output log files. translate already existsr(602);If the file does already exist and you wish to overwrite the existing copy, you can specify thereplaceoption:. translate , replaceSee [R]translatefor more Windows and Mac, you can also convert yourSMCL file to aPDFto share it more easily withothers:. translate [R]translatefor more you prefer, you can skip theSMCLand create text logs directly, either by specifying that youwant the log intextformat,. log using session, textor by specifying that the file to be created be :. log using Appending to an existing logStata never lets you accidentally write over an existing log file.
6 If you have an existing log fileand you want to continue logging, you have three choices: create a new log file append the new log onto the existing log file by typinglog usinglogname, append replace the existing log file by typinglog usinglogname, replaceFor example, if you have an existing log file , you might type. log using session, appendto append the new log to the end of the existing log file, Suspending and resuming loggingOnce you have started logging your session, you can turn logging on and off. When you turnlogging off, Stata temporarily stops recording your session but leaves the log file open. When youturn logging back on, Stata continues to record your session, appending the additional record to theend of the that the first time something interesting happens, you typelog using results(or click onLogand ). You then retype the command that produced the interesting result (ordouble-click on the command in the Review window, or use thePgUpkey to retrieve the command;see[U] 10 Keyboard use).
7 You now have a copy of the interesting result saved in the log are now reasonably sure that nothing interesting will occur, at least for a while. Rather thantypelog close, however, you typelog off, or you click onLogand chooseSuspend. From nowon, nothing goes into the file. The next time something interesting happens, you typelog on(orclick onLogand chooseResume) and reissue the (interesting) command. After that, you typelogoff. You keep working like this toggling the log on and off.[ U ] 15 Saving and printing output log files Placing comments in logsStata treats lines starting with a * as comments and ignores them. Thus, if you are workinginteractively and wish to make a comment, you can type * followed by your comment:. * check that all the spells are ignores your comment, but if you have a log going the comment now appears in the notelogcan be combined with#review(see[U] 10 Keyboard use) to bail you out when you havenot adequately planned ahead.
8 Say that you have been working in front of your computer, and younow realize that you have done what you wanted to do. Unfortunately, you are not sure exactly whatit is you have done. Did you make a mistake? Could you reproduce the result? Unfortunately, youhave not been logging your output. Typing#reviewwill allow you to look over what commandsyou have issued, and, combined withlog, will allow you to make a record. You can also see thecommands that you have issued in the Review window. You can save those commands to a file byselecting the commands to save, right-clicking on the Review window, and selectingSave usingfilename. Type#review 100. Stata will list the last 100 commands you gave,or however many it has stored. Becauselogis making a record, that list will also be stored in thefile. Finally, typelog Logging only what you typeLog files record everything that happens during a session, both what you type and what Stataproduces in can also produce command log files files that contain only what you type.
9 These files areperfect for later going back and creating a Stata command log files, and its basic syntax iscmdlog usingfilename[, append replace] offtemporarily suspends command loggingcmdlog onresumes command loggingcmdlog closecloses the command log fileSee [R]logfor all the logs are plain text files. If you typed. cmdlog using session(cmdlog C:\example\ opened). use (Census Data). tabulate region [freq=pop](output omitted). summarize median_age(output omitted). cmdlog close(cmdlog C:\example\ closed)6 [ U ] 15 Saving and printing output log containuse region [freq=pop]summarize median_ageYou can create both kinds of logs full session logs and command logs simultaneously, if youwish. A command log file can later be used as a do-file; see [R] The log-button alternativeThe capabilities of thelogcommand (but not thecmdlogcommand) are available from Stata sGUIinterface; just click on theLogbutton or selectLogfrom can use the Viewer to view logs, even logs that are in the process of being created.
10 Just selectFile > If you are currently logging, the filename to view will already be filled in with thecurrent log file, and all you need to do is click onOK. Periodically, you can click on theRefreshbutton to bring the Viewer up to can also use the Viewer to view previous can access the Viewer by selectingFile > , or you can use theviewcommand:. view printing logsYou print logs from the Viewer. SelectFile > , or typeviewlogfilenamefrom the commandline to load the log into the Viewer, and then right-click on the Viewer and can also print logs by other means; see [R] Creating multiple log files for simultaneous useProgrammers or advanced users may want to create more than one log file for simultaneous example, you may want a log file of your whole session but want a separate log file for part ofyour can create multiple logs by usinglog sname()option; see [R]log.