Hello, I have 4 different binary variables. I want to combine all the 1s (yes) from each of these 4 into a single variable that I can then use to run a multinomial model.
The variables are: sexptnrs_2plus sex_nonspousal noncondomuse_2more noncondomuse_nonspouse. Each is coded 1/0; the last 2 have some missing values.
gen riskprofile=0
replace riskprofile=1 if sexptnrs_2plus==1
replace riskprofile=2 if sex_nonspousal==1
replace riskprofile=3 if noncondomuse_2more==1
replace riskprofile=4 if noncondomuse_nonspousal==1
replace riskprofile=. if sexptnrs_2plus==. | sex_nonspousal==. | noncondomuse_2more==. | noncondomuse_nonspousal==.
fre riskprofile
I tried this code but got values that are lower than the number of valid 1s in each original variable. Below I provided a copy of the individual frequencies and the resulting variable I generated.
Below, also is an example of my crdatch dataset
Thanks in advance for any assistance. Sincerely, Cy
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
The variables are: sexptnrs_2plus sex_nonspousal noncondomuse_2more noncondomuse_nonspouse. Each is coded 1/0; the last 2 have some missing values.
gen riskprofile=0
replace riskprofile=1 if sexptnrs_2plus==1
replace riskprofile=2 if sex_nonspousal==1
replace riskprofile=3 if noncondomuse_2more==1
replace riskprofile=4 if noncondomuse_nonspousal==1
replace riskprofile=. if sexptnrs_2plus==. | sex_nonspousal==. | noncondomuse_2more==. | noncondomuse_nonspousal==.
fre riskprofile
I tried this code but got values that are lower than the number of valid 1s in each original variable. Below I provided a copy of the individual frequencies and the resulting variable I generated.
Below, also is an example of my crdatch dataset
Thanks in advance for any assistance. Sincerely, Cy
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long v001 int(v002 v003) float(sexptnrs_2plus sex_nonspousal noncondomuse_2more noncondomuse_nonspousal) 1 1 1 1 0 1 . 1 1 2 0 0 . . 1 1 3 1 1 1 1 1 2 1 1 0 1 . 1 2 2 0 0 . . end label values sexptnrs_2plus yesno label values sex_nonspousal yesno label values noncondomuse_2more yesno label values noncondomuse_nonspousal yesno label def yesno 0 "No", modify label def yesno 1 "Yes", modify
------------------ copy up to and including the previous line ------------------
Code:
sexptnrs_2plus -- Have two or more sexual partners in the past 12 months
-----------------------------------------------------------
| Freq. Percent Valid Cum.
--------------+--------------------------------------------
Valid 0 No | 316403 92.11 92.11 92.11
1 Yes | 27114 7.89 7.89 100.00
Total | 343517 100.00 100.00
-----------------------------------------------------------
sex_nonspousal -- Sex with non-spousal/cohabiting partner in the past 12m
-----------------------------------------------------------
| Freq. Percent Valid Cum.
--------------+--------------------------------------------
Valid 0 No | 276349 80.45 80.45 80.45
1 Yes | 67168 19.55 19.55 100.00
Total | 343517 100.00 100.00
-----------------------------------------------------------
noncondomuse_2more -- Did not use condom with two or more sexual partners - last sex
-----------------------------------------------------------
| Freq. Percent Valid Cum.
--------------+--------------------------------------------
Valid 0 No | 8609 2.51 30.29 30.29
1 Yes | 19812 5.77 69.71 100.00
Total | 28421 8.27 100.00
Missing . | 315096 91.73
Total | 343517 100.00
-----------------------------------------------------------
noncondomuse_nonspousal -- Did Not Used Condom with non-spousal/cohabiting partner in the past 12 months
-----------------------------------------------------------
| Freq. Percent Valid Cum.
--------------+--------------------------------------------
Valid 0 No | 32882 9.57 48.95 48.95
1 Yes | 34286 9.98 51.05 100.00
Total | 67168 19.55 100.00
Missing . | 276349 80.45
Total | 343517 100.00
-----------------------------------------------------------
riskprofile
-----------------------------------------------------------
| Freq. Percent Valid Cum.
--------------+--------------------------------------------
Valid 0 | 268676 78.21 78.21 78.21
1 | 232 0.07 0.07 78.28
2 | 29154 8.49 8.49 86.77
3 | 11169 3.25 3.25 90.02
4 | 34286 9.98 9.98 100.00
Total | 343517 100.00 100.00
-----------------------------------------------------------
Comment