So I have these overly complicated IF statements and I need to run to compute a new variable. But I need to do the same computation for 30 occasions. So basically I need to end up with 30 new variables- Participation_1 to Participation_30. The othervariable names change the same way _1 to _30.
I assume its a loop? not sure how to write it though?
The variables are all numeric
DO IF (MISSING(CurrentlyStudying_status_1) AND MISSING(CurrentlyEmployed_1) AND MISSING(LookingForWork_1)).
COMPUTE Participation_1 = $SYSMIS.
ELSE IF (CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 0 AND LookingForWork_1 = 6).
COMPUTE Participation_1 = 0.
ELSE IF (CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 0 AND LookingForWork_1 = 9).
COMPUTE Participation_1 = 1.
ELSE IF (CurrentlyEmployed_1 = 2 AND CurrentlyStudying_status_1 = 0
OR CurrentlyEmployed_1 = 1 AND CurrentlyStudying_status_1 = 0
OR CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 1).
COMPUTE Participation_1 = 2.
ELSE IF (CurrentlyEmployed_1 = 2 AND CurrentlyStudying_status_1 = 1
OR CurrentlyEmployed_1 = 1 AND CurrentlyStudying_status_1 = 1
OR CurrentlyEmployed_1 = 3 OR CurrentlyStudying_status_1 = 1).
COMPUTE Participation_1 = 3.
END IF.
EXECUTE.
So I have these overly complicated IF statements and I need to run to compute a new variable. But I need to do the same computation for 30 occasions. So basically I need to end up with 30 new variables- Participation_1 to Participation_30. The othervariable names change the same way _1 to _30.
I assume its a loop? not sure how to write it though?
The variables are all numeric
DO IF (MISSING(CurrentlyStudying_status_1) AND MISSING(CurrentlyEmployed_1) AND MISSING(LookingForWork_1)).
COMPUTE Participation_1 = $SYSMIS.
ELSE IF (CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 0 AND LookingForWork_1 = 6).
COMPUTE Participation_1 = 0.
ELSE IF (CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 0 AND LookingForWork_1 = 9).
COMPUTE Participation_1 = 1.
ELSE IF (CurrentlyEmployed_1 = 2 AND CurrentlyStudying_status_1 = 0
OR CurrentlyEmployed_1 = 1 AND CurrentlyStudying_status_1 = 0
OR CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 1).
COMPUTE Participation_1 = 2.
ELSE IF (CurrentlyEmployed_1 = 2 AND CurrentlyStudying_status_1 = 1
OR CurrentlyEmployed_1 = 1 AND CurrentlyStudying_status_1 = 1
OR CurrentlyEmployed_1 = 3 OR CurrentlyStudying_status_1 = 1).
COMPUTE Participation_1 = 3.
END IF.
EXECUTE.
So I have these overly complicated IF statements and I need to run to compute a new variable. But I need to do the same computation for 30 occasions. So basically I need to end up with 30 new variables- Participation_1 to Participation_30. The othervariable names change the same way _1 to _30.
I assume its a loop? not sure how to write it though?
The variables are all numeric
DO IF (MISSING(CurrentlyStudying_status_1) AND MISSING(CurrentlyEmployed_1) AND MISSING(LookingForWork_1)).
COMPUTE Participation_1 = $SYSMIS.
ELSE IF (CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 0 AND LookingForWork_1 = 6).
COMPUTE Participation_1 = 0.
ELSE IF (CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 0 AND LookingForWork_1 = 9).
COMPUTE Participation_1 = 1.
ELSE IF (CurrentlyEmployed_1 = 2 AND CurrentlyStudying_status_1 = 0
OR CurrentlyEmployed_1 = 1 AND CurrentlyStudying_status_1 = 0
OR CurrentlyEmployed_1 = 0 AND CurrentlyStudying_status_1 = 1).
COMPUTE Participation_1 = 2.
ELSE IF (CurrentlyEmployed_1 = 2 AND CurrentlyStudying_status_1 = 1
OR CurrentlyEmployed_1 = 1 AND CurrentlyStudying_status_1 = 1
OR CurrentlyEmployed_1 = 3 OR CurrentlyStudying_status_1 = 1).
COMPUTE Participation_1 = 3.
END IF.
EXECUTE.
@Rich, that makes sense to me, and I have created new variables that have values only in the required range for the temp table, but I am not familar with a logical table or how to create one? Im keen to give it a go.
Thanks to you both
Variables are:
CurrentlyEmployed (0,1,2,3)
CurrentlyStudying_status (0,1,2)
LookingForWork_status (0,1)
On Friday, August 21, 2020 at 1:17:53 AM UTC-4, Erin Holloway wrote:untested, as I do not have your dataset. But I think it ought to work. But as before, you have to fill in the details of the RECODE command, because only you know the rules for that.
Thanks to you both--- snip ---
Variables are:
CurrentlyEmployed (0,1,2,3)
CurrentlyStudying_status (0,1,2)
LookingForWork_status (0,1)
Here is another variation on Rich's theme which *might* be a bit easier to follow. I start with a self-contained version to demonstrate the concept--hence the "toy" dataset.
* Generate a toy dataset with all combinations of those variables.
NEW FILE.
DATA LIST LIST / ce cs lw (3F1.0).
BEGIN DATA
0 0 0
0 0 1
0 0 .
0 1 0
0 1 1
0 1 .
0 2 0
0 2 1
0 2 .
0 . 0
0 . 1
0 . .
1 0 0
1 0 1
1 0 .
1 1 0
1 1 1
1 1 .
1 2 0
1 2 1
1 2 .
1 . 0
1 . 1
1 . .
2 0 0
2 0 1
2 0 .
2 1 0
2 1 1
2 1 .
2 2 0
2 2 1
2 2 .
2 . 0
2 . 1
2 . .
3 0 0
3 0 1
3 0 .
3 1 0
3 1 1
3 1 .
3 2 0
3 2 1
3 2 .
3 . 0
3 . 1
3 . .
. 0 0
. 0 1
. 0 .
. 1 0
. 1 1
. 1 .
. 2 0
. 2 1
. 2 .
. . 0
. . 1
. . .
END DATA.
FREQUENCIES ce cs lw.
* [1] Recode SYSMIS to 9, but do not (yet) treat it as missing.
* This will allow step 2 below to work properly.
RECODE ce cs lw (SYSMIS=9).
FREQUENCIES ce cs lw.
* [2] Combine the 3 variables into a single variable.
COMPUTE cecslw = ce*100 + cs*10 + lw.
FORMATS cecslw (F3.0).
FREQUENCIES cecslw.
* [3] RECODE cecslw into new variable Part.
* You'll have to fill in the value lists and values according to your rules. >RECODE cecslw
(999 = 999)
(value list = value)
(value list = value)
etc.
(value list = value) INTO Part.
FORMATS Part (F5.0).
MISSING VALUES Part (999) / ce cs lw (9).
FREQUENCIES Part.
* --------------------------------------.
Now here it is inserted in a DO-REPEAT structure that allows you to loop through your 30 variables. Notice that I have changed variable cecslw to #cecslw. The # makes it a scratch variable that will not be written to your dataset. This bit is
DO REPEAT
cs = CurrentlyStudying_status_1 to CurrentlyStudying_status_30 /
ce = CurrentlyEmployed_1 to CurrentlyEmployed_30 /
lw = LookingForWork_1 to LookingForWork_30 /
part = Participation_1 to Participation_30.
RECODE ce cs lw (SYSMIS=9).
COMPUTE #cecslw = ce*100 + cs*10 + lw.
RECODE #cecslw
(999 = 999)
(value list = value)
(value list = value)
etc.
(value list = value) INTO Part.
END REPEAT.
MISSING VALUES Participation_1 to Participation_30 (999).
HTH.
Alright, its working! I have re-calculated the variables so css and ces = 0,1,2 and lws = 0,1. So its clearer with the culculation which is which.
Thank you so so much. This has been driving me nuts for ages.
Erin
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 429 |
Nodes: | 16 (2 / 14) |
Uptime: | 113:27:27 |
Calls: | 9,055 |
Calls today: | 2 |
Files: | 13,395 |
Messages: | 6,016,252 |