Solved
Contributor
Posts: 62

efficicient coding

Hello,

I have a dataset of patients who reported alcohol consumption during the last  3 months,see below

What would be the most efficient  way of coding the patients into  three categories

1- No alcohol drink during the last 3 months

2-moderate  alcohol consumption ( those who reported drinking 25 glasses per month)

3-Excessive alcohol consumption ( those who reported drinking more than 25 glasses  per month

Thank you.

data alcohol;
input ID month1 month2 month3;
datalines;

 30300 0 0 3 30301 3 3 6 30302 0 0 0 30303 10 35 35 30390 20 22 21 30391 0 0 0 30392 9 20 22 30393 67 90 45 30501 12 11 32 30500 4 12 19 30502 2 4 2 30503 1 2 2

;

Accepted Solutions
Solution
‎11-21-2016 04:00 PM
Posts: 5,532

Re: efficicient coding

[ Edited ]
``````mm = max(of month:);
if mm > 25 then cat = 3;
else if mm > 0 then cat = 2;
else cat = 1;
drop mm;``````
PG

All Replies
Solution
‎11-21-2016 04:00 PM
Posts: 5,532

Re: efficicient coding

[ Edited ]
``````mm = max(of month:);
if mm > 25 then cat = 3;
else if mm > 0 then cat = 2;
else cat = 1;
drop mm;``````
PG
Contributor
Posts: 62

Re: efficicient coding

This is great!! Thank you very much.

One more question, if  the month variable was such as alco_month_1, alco_month_2, and alco_month_last, how can this be  tranformed mm = max(of month:) ?

Posts: 5,532

Re: efficicient coding

``mm = max(of alco_month_:);``
PG
Contributor
Posts: 62

Re: efficicient coding

Thanks!!

☑ This topic is solved.