Introduction to Stata 8 - (GRIPS
Introduction to Stata 8 - (GRIPS
Introduction to Stata 8 - (GRIPS
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
10.2. Selections<br />
Selecting observations [GSW] 13; [R] drop<br />
You may remove observations from the data in memory by:<br />
keep if sex == 1 or, with the same effect:<br />
drop if sex != 1<br />
You may restrict the data in memory <strong>to</strong> the first 10 observations:<br />
keep in 1/10<br />
A selection may be requested already when opening a data set:<br />
use c:\dokumenter\p1\a.dta if sex == 1<br />
use c:\dokumenter\p1\a.dta in 1/10<br />
Observations dropped can only be returned <strong>to</strong> memory with a new use command.<br />
Selecting variables [GSW] 13; [R] drop<br />
You may remove variables from the data in memory by:<br />
keep sex age-weight and by:<br />
drop sex age-weight<br />
A selection may be requested already when opening a data set:<br />
use sex age-weight using c:\dokumenter\p1\a.dta<br />
Sampling [R] sample<br />
Keep a 10% random sample of the observations:<br />
sample 10<br />
To obtain a sample of exactly 57 observations:<br />
sample 57 , count<br />
10.3. Renaming and reordering variables<br />
Renaming variables [R] rename<br />
rename koen sex<br />
The variable name koen is changed <strong>to</strong> sex. Contents and labels are unchanged.<br />
Reordering variables [R] order<br />
To change the sequence of variables specify:<br />
order id age-weight<br />
The new sequence of variables will be as defined. Any variables not mentioned will follow<br />
after the variables mentioned.<br />
23