04.06.2013 Views

Introduction to Stata 8 - (GRIPS

Introduction to Stata 8 - (GRIPS

Introduction to Stata 8 - (GRIPS

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.

y and bysort prefix [U] 14.5<br />

Makes a command display results for subgroups of the data. Data must be pre-sorted:<br />

sort sex<br />

by sex: summarize age height weight<br />

or, in one line:<br />

bysort sex: summarize age height weight<br />

Text strings, quotes<br />

<strong>Stata</strong> requires double quotes around text strings, but you may omit quotes unless the string has<br />

embedded blanks or commas:<br />

label define sex 1 male 2 female 9 "sex unknown"<br />

You need not use quotes around filenames:<br />

save c:\dokumenter\proj1\alfa1.dta<br />

unless they include blank space:<br />

save "c:\dokumenter\project 1\alfa1.dta"<br />

Comments [U] 19.1.2<br />

The following is interpreted as comments, <strong>to</strong> include short explanations in a do-file:<br />

• Lines that begin with *<br />

• text surrounded by /* and */<br />

• Text following // (the easy way; used in this booklet)<br />

The purpose of comments is <strong>to</strong> make do-files more readable <strong>to</strong> yourself – <strong>Stata</strong> does not care<br />

whatever you write.<br />

// C:\DOKUMENTER\PROFILE.DO executes when opening <strong>Stata</strong><br />

summarize bmi , detail // Body mass index<br />

Long command lines [U] 19.1.3<br />

By default a command ends when the line ends (carriage return), and no special delimiter<br />

terminates commands. However, command lines in do- and ado-files should be no longer than<br />

80 characters. The problem is solved by /// signalling that the following line is a<br />

continuation.<br />

infix str10 cprstr 1-10 bday 1-2 bmon 3-4 byear 5-6 ///<br />

control 7-10 using c:\dokumenter\p1\datefile.txt<br />

Another option is <strong>to</strong> define ; (semicolon) as the future command delimiter:<br />

#delimit ; // Semicolon delimits future commands<br />

infix str10 cprstr 1-10 bday 1-2 bmon 3-4 byear 5-6<br />

control 7-10 using c:\dokumenter\p1\datefile.txt ;<br />

tab1 opagr ;<br />

#delimit cr // Back <strong>to</strong> normal: Carriage return delimiter<br />

15

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

Saved successfully!

Ooh no, something went wrong!