1.9. Basic String Functions¶
Consider the NC Birth dataset once again.
Suppose our goal is to create a new variable that combines Father Minority and Mother Minority. Note that there should be four possible combinations – Nonwhite / Nonwhite, Nonwhite / White, White / Nonwhite, and White / White.
One possible approach we could take is to filter on each variable and then simply type in the value for the new variable in the first cell. This cell could then be copied down to fill in the remaining cells for this particular combination.
Next, we could copy this down for all Nonwhite / Nonwhite cells.
Similarly, we could do this for the Nonwhite/White and other combinations.
After completing all four combinations, it may appear as though we are done; however, consider Patients 4 and 17.
A second approach is to create the new variable using the
=CONCATENATE()
function. Consider the following use of the
CONCATENATE function. Copy this function down for all observations.
Note:
You can automatically fill the entire column by double clicking the lower-right corner of CELL F2.
Question:
What happens to Patients 4 and 17 when the CONCATENATE()
function is
used?
1.9.1. Pulling a Variable Apart¶
Suppose that we were given only the column Father / Mother Minority and that we wanted to separate this into two variables: Father Minority and Mother Minority. This task could be accomplished as follows.
Step 1: Find the “/”.
A description of the FIND
function from the Excel help documentation:
Question
What value does the function entered in cell G2 return?
Step 2: Get everything before the “/” for Father Minority.
Note that we can use the =MID()
function to do this.
A description of the MID
function from the Excel help documentation:
What is the problem with the formula as entered above in cell H2?
To remedy this, make the following modification:
The result…
TASK:
Use a similar approach to get Mother Minority on its own in Column I. Below, write the formula you would use in cell I2 to accomplish this.
There are several other string functions available in Excel that are worth noting. Read through each of the following function descriptions. If you’re not sure how a function works, use the Excel help documentation to learn more about and/or experiment with the function to figure it out.