Introduction to Stata 8
Introduction to Stata 8
Introduction to Stata 8
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
8. Getting data in<strong>to</strong> <strong>Stata</strong> [U] 24; [GSW] 7<br />
On exchange of data with other programs, see section 15.8.<br />
Open <strong>Stata</strong> data [R] save<br />
Read an existing <strong>Stata</strong> data set from disk in<strong>to</strong> memory by:<br />
use c:\dokumenter\p1\a.dta [ , clear]<br />
If there are data in memory, use will be rejected unless you specify the clear option.<br />
You may also issue a clear command before the use command:<br />
clear<br />
If you want only observations that meet a condition:<br />
use c:\dokumenter\p1\a.dta if sex==1<br />
If you want the first 100 observations only:<br />
use c:\dokumenter\p1\a.dta in 1/100<br />
If you want <strong>to</strong> work with only a subset of variables:<br />
use age sex q1-q17 using c:\dokumenter\p1\a.dta<br />
Save <strong>Stata</strong> data [R] save<br />
Save the data in memory <strong>to</strong> a disk file by:<br />
save c:\dokumenter\p1\a.dta [ , replace]<br />
If you already have a disk file with this name, your request will be rejected unless you specify<br />
the replace option. Only use the replace option if you really want <strong>to</strong> overwrite data.<br />
Enter data with EpiData<br />
To enter data I recommend EpiData, available for free from www.epidata.dk. This easy-<strong>to</strong>use<br />
program has all the facilities needed. Further information in appendix 2.<br />
Enter data as commands or in a do-file [R] input<br />
Very small data sets. Define the variables with the input command and enter the values.<br />
Finish with end. It can be done interactively from the command line or in a do-file. See<br />
more examples in section 14.7 (Graph examples).<br />
. input case expos pop<br />
0 0 100<br />
0 1 30<br />
1 0 23<br />
1 1 21<br />
. end<br />
You may also enter data directly in <strong>Stata</strong>'s data window (not recommended; see section 2 and<br />
[GSW] 6, 9).<br />
16