Steps in creating a dataset

1. Select observations.

2. Select variables.

3. Create new variables.

4. Add variable labels.

5. Add notes to variables.

6. Add value labels.

7. Rearranging variables.

8. Add internal documentation.

9. Add a datasignature.

10. Save the dataset.

11. SUMMARY of key commands.

Note
For naming conventions for datasets, see Workflow style conventions.

1. Select 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 in numeric list

For example:

drop in 1/22

2. Select 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]

Remember that if a variable is new, give it a new name.
Verify that new variables are constructed correctly.
Keep source variables used to create new variables.

4. New variables should have a variable label

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. New variables should have notes documenting their provenance

note variable name "variable label"

For example:

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

6. Add value labels to all categorical 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. Add internal documentation to 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. Add a datasignature.

datasignature set

To confirm:

use wf-datasig02, clear
datasignature confirm

To change the signature after modifications to the dataset:

datasignature set, reset

10. Save the dataset

quietly compress
saveold mydata, replace

12. Summary of key commands

keep if exp
drop if exp

keep in numeric list
drop in numeric list

keep variable list
drop variable list

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

label variable varname "label"
note variable name "variable label"

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

aorder [varlist]
order varlist

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

datasignature set
datasignature set, reset

quietly compress
saveold mydata, replace