10.08.2013 Views

Introduction to Stata 8

Introduction to Stata 8

Introduction to Stata 8

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 3. Analyse <strong>Stata</strong> data<br />

// winedes.do Descriptive analysis of the wine data 14.5.2001<br />

use c:\dokumenter\wines\wine.dta<br />

describe<br />

codebook<br />

summarize<br />

tab1 type rating<br />

tabulate type rating , chi2 exact<br />

oneway price rating , tabulate<br />

Note that in example 1 and 2 the structure was:<br />

1. Read data (infix, use)<br />

2. Calculation and documentation commands<br />

3. Save data (save)<br />

In these examples a new generation of the data was created; changes were documented with a<br />

do-file with a gen. prefix.<br />

In example 3 the structure was:<br />

1. Read data (use)<br />

2. Analysis commands<br />

No new data generation was created, and the gen. prefix does not belong <strong>to</strong> such do-files.<br />

Example 4. Elaborate profile.do<br />

/ / c:\ado\personal\profile.do executes au<strong>to</strong>matically when opening <strong>Stata</strong>.<br />

// Write session start time in time.txt.<br />

set obs 1<br />

gen time="******* Session started: `c(current_date)' `c(current_time)'"<br />

outfile time using c:\tmp\time.txt, noquote replace<br />

clear<br />

// Copy session start time <strong>to</strong> the cmdlog (cmdlog.txt) and open it.<br />

// ! means that a DOS command follows.<br />

! copy /b c:\tmp\cmdlog.txt + c:\tmp\time.txt c:\tmp\cmdlog.txt /y<br />

cmdlog using c:\tmp\cmdlog.txt , append<br />

//<br />

Open the log (stata.log).<br />

set logtype text<br />

log using c:\tmp\stata.log , replace<br />

Compared <strong>to</strong> the profile.do suggested in section 1.2, this version adds a time stamp <strong>to</strong><br />

the command log file (cmdlog.txt). This means better possibilities <strong>to</strong> reconstruct previous<br />

work.<br />

66

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

Saved successfully!

Ooh no, something went wrong!