How to Recode Continuous Vars in Stata

Recoding into a different variable transforms an original variable into a new variable. That is, the changes do not overwrite the original variable; they are instead applied to a copy of the original variable under a new name.

To recode into different variables, clickTransform > Recode into Different Variables.

The Recode into Different Variables window will appear.

The left column lists all of the variables in your dataset. Select the variable you wish to recode by clicking it. Click the arrow in the center to move the selected variable to the center text box, (B).

A Input Variable -> Output Variable:The center text box lists the variable(s) you have selected to recode, as well as the name your new variable(s) will have after the recode. You will define the new name in (C).

B Output Variable: Define the name and label for your recoded variable(s) by typing them in the text fields. Once you are finished, click Change. Now the center text box, (B), will display both the name of the original variable as well as the name for the new variable (e.g., "Height --> Height_categ").

C Old and New Variables: Click the Old and New Values to specify how you wish to recode the values for the selected variable.

D If: The If  option allows you to specify the conditions under which your recode will be applied. (We discuss the If option in more detail later in this tutorial.)


Old and New Values

Once you clickOld and New Values, a new window where you will specify how to transform the values will appear.

1 Old Value: Specify the type of value you wish to recode (e.g., a specific value, missing data, or a range of values) and the specific value to be recoded (e.g., a value of "1" or a range of "1-5").

When recoding variables, always handle the missing values first! The most common recoding errors happen when you don't tell SPSS explicitly what to do with missing values: SPSS may recode missing values into one of the new valid categories. This is especially true if using the "Lowest thru", "thru Highest", or "Range - through" options.

  • Value: Enter a specific numeric code representing an existing category.
  • System-missing: Applies to any system-missing values (.)
  • System- or user-missing: Applies to any system-missing values (.) or special missing value codes defined by the user in the Variable View window
  • Range: For use with ordered categories or continuous measurements. Enter the lower and upper boundaries that should be coded. The recoded category will include both endpoints, so data values that are exactly equal to the boundaries will be included in that category.
  • Range, LOWEST through value: For use with ordered categories or continuous measurements. Recode all values less than or equal to some number.
  • Range, value through HIGHEST: For use with ordered categories or continuous measurements. Recode all values greater than or equal to some number.
  • All other values : Applies to any value not explicitly accounted for by the previous recoding rules. If using this setting, it should be applied last.

2 New Value: Specify the new value for your variable (i.e., a specific numeric code such as "2," system-missing, or copy old values).

3 Old -> New: Once you have selected the old and new values for your selected variable in (1) and (2), click Add in area (3), Old-->New. The recode that you have specified now appears in the text field. If you need to change one of the recodes that you have added to the Old-->New area section, simply click on the one you wish to change and make changes in (1) and (2) as necessary.

You will need to repeat these steps for each value that you wish to recode. Once you have specified all the transformations that you wish to make for the selected variable, click the "Continue" button.

4 Output variables are strings and Convert numeric strings to numbers: These options change the variable type of the new variable.

  • Output variables are strings: The new variable will be a string variable.
  • Convert numeric strings to numbers: This option can only be used when your input variable is a string, and will be grayed out otherwise. If the input variable is a string, but the data values themselves are valid numbers, selecting this option will convert the number strings into actual numbers. (If any other character symbols appear in the data values, the conversion will fail, even if the numbers are otherwise valid. This includes dollar signs and percent symbols.)

The "If" option

Sometimes you may wish to recode values for a specific variable only when other conditions in your data are satisfied. This means that cases meeting the conditions will be recoded, and cases not meeting the conditions will be assigned a missing value. To specify such conditions, click If to bring up the Recode into Different Variables: If Cases window.

1 The left column displays all of the variables in your dataset. You will use one or more variables to define the conditions under which your recode should be applied to the data.

2 The default specification for a recode is to Include all cases. To specify the conditions under which the recode should be applied, however, you will need to click Include if case satisfies condition. This will allow you to specify the conditions under which the recode will be applied to your data.

3 The center of the window includes a collection of arithmetic operators, Boolean operators, and numeric characters, which you can use to specify the conditions under which your recode will be applied to the data. There are many kinds of conditions you can specify by selecting a variable (or multiple variables) from the left column, moving them to the center text field, and using the blue buttons to specify values (e.g., "1") and operations (e.g., +, *, /). You can also use the options in the Function group list.

4 The Function Group box contains common functions that may be used for calculating values for new variables (e.g., mean, logarithm, sine). After selecting a category, you will see function names appear in the Functions and Special Variables box. Double-clicking on a function name will add it to the "Include if case satisfies condition" box.

When you are finished defining the conditions under which your recode will be applied to the data, click Continue.

Note: Recode into Different Variables does not include the ability to add value labels to the new categories, so immediately after recoding, you should add value labels to your new numeric codes.

When you are ready to run the procedure, clickOK. Now your new variable will be recoded according to the criteria you specified. You can find your new variable in the last column in Data View or in the last row of Variable View.

beaudoinsprinstif.blogspot.com

Source: https://libguides.library.kent.edu/SPSS/RecodeVariables

0 Response to "How to Recode Continuous Vars in Stata"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel