Exercise 2:  Create new variables, code and label variables.

This exercise will use demo2 project. If you have not started demo2 project, click here to follow exercise 1: start the new project demo2

·         Open demo2 project

·         Create SMK, Code & label SMK

·         Create EDUC, Code & label EDUC

·         Create BMI, Label BMI

·         Create BMI3

·         Create SNP1, Code & label SNP1

·         Code & label SEX, OCCU and ALH

 

===========================================================================================

Open demo2 project

·         Open Empower(R), login and then click “Start”

·         Click “Project” menu and then click “Open”, in popup window select “…\My documents\EmpowerStats Files\EmpowerR_demos\demo2\demo2.ini”

SNAGHTML5ed27c

·         Click “Open” button.

 

Create SMK:  Variable SMOKE original coding is: 0=never smoke, 1=former smoker, 2=current smoker, since very fewer people in category 1 (former smoker), we want to combine former smoke with current smoker, create a new variable SMK to indicate cigarette smoking (0=no 1=yes)

·         Right click variable SMOKE, then click “Recode” in the popup menu.  You will see following new window.

              SNAGHTML13f546

·         In the above “Recode Categorical Variable” window, right click code “2” and then click “1” in the popup window.  That is to recode “2” to “1”.

              

·         Click new variable name “SMOKE.NEW” in the above “Recode Categorical Variable” window, change SMOKE.NEW to SMK as the new variable name.

             SNAGHTML16e8c8

·         Click OK, then “Save” in the above “Recode Categorical Variable” window, done!  You will see a new variable SMK added to variables list.

 

Coding and label variable SMK

·         Right click variable SMK in variables list, then click “Code & label” in popup menu

·         Enter “Cigarette smoking” as the label of SMK, and click 0=no 1=yes as the coding of SMK

SNAGHTML3bbd08

Click “Save -> Exit”, you will see variable SMK’s labeling and coding in the panel for variables list.

 

Create EDUC:  Variable EDU was originally coded as “1=elementary or lower 2=middle school 3=high school 4=college or above”, since category 4 (college or above) has very few people, we want to combine category 4 with category 3, give code 3 new definition as “high school or above”, and create a new variable EDUC.

·         Right click variable EDU, then click “Recode” in the popup menu.  You will see following new window.

SNAGHTML25c071

·         In the above “Recode Categorical Variable” window, right click code “4” and then click “3” in the popup window.  That is to recode “4” to “3”.

·         Click new variable name “EDU.NEW” in the above “Recode Categorical Variable” window, change EDU.NEW to EDUC as the new variable name.

SNAGHTML261e4a

·         Click OK, then “Save” in the above “Recode Categorical Variable” window, done!  You will see a new variable EDUC added to variables list.

 

Coding and label variable EDUC

·         Right click variable EDUC in variables list, then click “Code & label” in popup menu

·         Enter “Education” as the label, and click “Save -> Next”,

·         Next is to label for EDUC=1, enter “Elementary or lower”, and then click “Save -> Next”

SNAGHTML3f77ee SNAGHTML47aa05

 

·         Next is to label for EDUC=2, enter “Middle school”, and then click “Save -> Next”

·         Next is to label for EDUC=3, enter “High school or above” and click “Save -> Exit”, you will see variable SMK’s labeling and coding in the panel for variables list.

 

SNAGHTML43a850 SNAGHTML43cf50

Done!

 

Create BMI:  apply BMI=WEIGHT/HEIGHT2

·         Right click the variables list, in popup menu select “Create new variable”.

·         In the popup window, enter BMI as new variable name.

SNAGHTML4e0722

·         In “Derive a new variable” window, enter “weight/height/height” as the formula for BMI, and then click “Save” button.

      SNAGHTML4db471

You will see a new variable BMI added to variables list.

 

Label variable BMI

·         Right click variable BMI in variables list, then click “Code & label” in popup menu

·         Enter “Body mass index” as the label, and click “Save -> Exit”.

SNAGHTML50ca32

You will see BMI label in variables list.

 

Create BMI3:  BMI is a continuous variable, we want to categorize it into tertiles (3 groups, each group has same number of observations), and name the new variable as BMI3 (0=low 1=middle, 2=high).

·         Right click variable BMI in variables list, then click “Categorize” in popup menu

·         Check “Tertiles” box, and click new name “BMI.T3”, in the popup window change the new variable name to “BMI3”

SNAGHTML687dd8    SNAGHTML697511

·         Click “Save” button in “Categorize a variable” window. 

 

Done!  You will see BMI3 added to variables list and it was automatically labeled as “Body mass index tertiles” and coded as “0=low 1=middle 2=high”.

 

Create SNP1:  Originally variable A11 and A12 were 2 allele variables for SNP1.  Check the variable A11’s and A12’s distribution, we found allele “10” is the common allele. Now we want to generate a new variable SNP1, code it as 0=AA (A11=10 and A12=10), 1=AB (A11=10 or A12=10), 2=BB (A11=20 and A12=20).

·         Right click variables list, click “Create new variable” in popup menu

·         Enter SNP1 as new variable name

SNAGHTML73b397

·         In “Derive a new variable” window:

o   Enter “a11=10 and a12=10” in “if” box, and enter “0” in “SNP1=” as the code, press “Enter” for “else if” box,

o   Enter “a11=10 or a12=10” in “else if” box, and enter “1” as the code for”SNP1=”, press “Enter” for next,

o   Enter “a11=20 and a12=20”, and enter “2” as the code.  Click “Save” button.

SNAGHTML740f8c

Done! You will see SNP1 added to variables list.

Coding and label variable SNP1

·         Right click variable SNP1 in variables list, then click “Code & label” in popup menu

·         Enter “SNP marker I” as the label, and click “Save -> Next”,

·         Next is to label for SNP1=0, enter “AA”, and then click “Save -> Next”

 SNAGHTMLcded3f SNAGHTMLce0a12

 

·         Next is to label for SNP1=1, enter “AB”, and then click “Save -> Next”

·         Next is to label for SNP1=2, enter “BB” and click “Save -> Exit”, you will see variable SNP1’s labeling and coding in the panel for variables list.

SNAGHTMLce3a74 SNAGHTMLce561f

 Done!

 

Code SEX:

·         Right click variable SEX, then click “Code & label” in popup menu

·         Check box “1=male 2=female” as the coding for SEX.

SNAGHTMLdaf78b

Done!

Code & label OCCU:

·         Right click variable OCCU, then click “Code & label” in popup menu

·         Enter “Occupation” as the label, click “Save -> Next”

·         Enter “Farmer” as label for OCCU=0, click “Save -> Next” and then enter “Others” as label for OCCU=1

·         Click “Save -> Exit”

SNAGHTMLdd671f SNAGHTMLdd8855 SNAGHTMLddb05f

Done!

Code & label ALH:

·          Right click variable ALH, then click “Code & label” in popup menu

·         Enter “Alcohol consumption” as label for ALH, and check box “0=no 1=yes” as the coding for ALH. Click “Save -> Exit”.

SNAGHTMLdf6b15

·         Done!