help wfdataset

Title

Steps when creating and saving a dataset

List of steps

1. Selecting observations.

2. Selecting variables.

3. Creating variables.

4. Adding variable labels.

5. Adding notes to variables.

6. Adding value labels.

7. Rearranging variables.

8. Internal documentation for a dataset.

9. Adding a datasignature.

10. Saving the dataset.

1. Selecting observations

Drop observations based on comparison

keep if exp
drop if exp

For example:

drop if female==1

Drop observations based on observation number

keep in numeric list
drop if numeric list

For example:

drop in 1/22

2. Selecting variables

keep variable list
drop variable list

For example:

drop female year tempvar
keep var1-var090

3. Create new variables

generate newvar = exp [if] [in]
clonevar newvar = sourcevar [if] [in]
replace newvar = exp [if] [in]

Principles for creating new variables

1. If a variable is new, give it a new name.

2. Verify that new variables are constructed correctly.

3. Document new variables with notes and labels.

4. Keep the source variables used to create new variables.

4. Adding variable labels

label variable varname "label"

For example:

label var artsqrt "Square root of # of articles"

Commands for listing variable labels and other information

codebook [varlist] [if] [in] , compact
describe [varlist] [if] [in] , simple fullnames numbers
nmlab varlist
tab1 varlist

5. Adding notes to variables

note variable name "variable label"

For example:

local tag "pub# truncated at 20 \ wf5-varnotes.do jsl 2008-04-09."
note pub1trunc: `tag'

6. Adding value labels to variables

Step 1: Defining labels (ideally, 10 characters or shorter)

label define Lyesno 1 1_yes 0 0_no

Step 2: Assigning labels

label value wc Lyesno

7. Rearranging variables.

aorder [varlist]
order varlist
move variable-to-move target-variable

For example:

aorder
order id

8. Internal documentation for a dataset.

label data "Workflow data from Russian ISSP 2002 \ 2008-04-02"
note: wf-isspru02.dta \ workflow ch 6 \ wf6-save.do jsl 2008-04-05

9. Adding a datasignature.

datasignature set

To confirm:

use wf-datasig02, clear
datasignature confirm

To change the signature after modifications to the dataset:

datasignature set, reset

11. Saving the dataset

quietly compress
saveold mydata, replace

Also see

wf