Task 4: How to Recode Variables Based on Alternate Definitions

This task reviews how to recode variables so they are appropriate for your analytic needs and how to check your derived variables.

 

Step 1 Recode based on alternate definitions

Recoding is an important step for preparing an analytical dataset.  In this step, you will view programs that recode variables using different techniques for each of the scenarios listed on the Clean & Recode Data: Key Concepts about Recoding Variables in NHANES II page. In the summary table below, each statement required for recoding is listed on the left with explanations on the right.

 

Program to Recode as Necessary Based on Alternate Definitions
Statements Explanation

data demo4_nh2;

      set demo3_nh2;

Use the data and set statements to refer to your analytic dataset.

if n2ah0064 = 1 then do;

 

if n2ah0062 <= 33 then HIGHSCHL= 1;

 else if n2ah0062= 34 then HIGHSCHL= 2;

 else if 41 <=n2ah0062<=45 then HIGHSCHL= 3;

 else HIGHSCHL= .;

 end ;

 

 if n2ah0064= 2 then do ;

 if n2ah0062= 34 then HIGHSCHL= 1;

 if n2ah0062= 41 then HIGHSCHL= 2;

 end ;

Use the if, then, and else statements to create a simple high school education categorical variable (HIGHSCHL) from two categorical education variables.

if (20 <=n2ah0047 <= 39) then

 age3cat=