11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

188 [ U ] 16 Do-filesMany users include the commands to start and stop the logging in the do-file itself:version 11log using myjob3, replace* a sample analysis jobuse censusbegin myjob3.dotabulate region// obtain summary statisticssummarize marriage_rate divorce_rate median_age if state!="Nevada"log closeend myjob3.doWe chose to open with log using myjob3, replace, the important part being the replace option.Had we omitted the option, we could not easily rerun our do-file. If myjob3.smcl had already existedand log was not told that it is okay to replace the file, the do-file would have stopped and insteadreported that “file myjob3.smcl already exists”. We could get around that, of course, by erasing thelog file before running the do-file.16.1.6 Preventing –more– conditionsAssume that you are running a do-file and logging the output so that you can look at it later. ThenStata’s feature of pausing every time the screen is full is just an irritation: it means that you have tosit and watch the do-file run so you can clear the more .The way around this is to include the line set more off in your do-file. Setting more to off, asexplained in [U] 7 –more– conditions, prevents Stata from ever issuing a more .16.2 Calling other do-filesDo-files may call other do-files. Say that you wrote makedata.do, which infiles your data,generates a few variables, and saves step1.dta. Say that you wrote anlstep1.do, which performeda little analysis on step1.dta. You could then create a third do-file,version 11do makedatado anlstep1begin master.doend master.doand so in effect combine the two do-files.Do-files may call other do-files, which, in turn, call other do-files, and so on. Stata allows do-filesto be nested 64 deep.Be not confused: master.do above could call 1,000 do-files one after the other, and still the levelof nesting would be only two.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!