I need to create a new variable (Var_new) out of the values of two old variables (Var_Old_1; Var_Old_2) but in both cases only for a subset of rows.
Let me explain:
I have an index variable, indicating the patient code; called "patientcode" (H01, H02, H03 ...)
I need to create a new variable. "Var_new"
the values of the new Variable "Var_new" must be assigned from Var_Old_1 or Var_Old_2 depending on the index variable.
So e.g.
for (H01, H02, H04) Var_new == Var_Old_1 for (H03, H05) Var_new == Var_Old_2
patientcode | Var_Old_1 | Var_Old_2 | Var_new |
---|---|---|---|
H01 | 1.1 | 2.1 | 1.1 |
H02 | 1.2 | 2.2 | 1.2 |
H03 | 1.3 | 2.3 | 2.3 |
H04 | 1.4 | 2.4 | 1.4 |
H05 | 1.5 | 2.5 | 2.5 |
This is only an example. In my dataset I'am dealing with 300 rows and I need to create 32 new variables following this scheme. so a good code would be helpful.