Hello Statalisters,
I am trying to calculate cumulative measures of alcohol consumption in my l dataset but its getting a bit complicated than smoking measures calculation. I have 9 episodes of drinking habit captured on all participants over their whole life in my data set (Sample data set given below) , with data on
a) Type of beverage they have used (1=wine, 2=beer, 3= hard liq, 4= Aperitif),
b) Start age of consumption in each episode, stop age of consumption in each episode,
c) Unit of alcohol consumed (1= 50 ml, 2= 100ml, 3=250ml, 4=330 ml, 5=725ml),
d) Consumption (how many units) ,
e) Frequency (1= per day, 2=per week, 3= per month).
Finally I want to calculate multiple measures of alcohol from this data. I want Number of Standard drinks of ethanol a) per day, b) per week, c) whole life , all in ml. I want number of grams of ethanol a) per day, b) per week, c) whole life. 1 Standard drink = 17.05 ml of ethanol or 13.5 g of ethanol. There is 0.789 g of ethanol per ml. It will be great if I could get these measures for all a) types of beverages combined b) each beverage separately (wine, beer, hard liq, Aperitif).
Codes that I tried out and Sample dataset with data on 11 participants are given below.
Two the scenarios that can complicate this calculation are:
a) A person might use multiple types of beverages and hence might have overlapping age periods (from and to ages) among any of the 9 episodes (e.g., 001-2, 1st episode is charecterised by this person drinking 2 medium glasses of wine/ month from 20 to 46 yrs of age. 2nd episode is characterised by 3 medium glasses of wine/week between 47 to 62 yrs. 3rd episode, 5 medium glasses of wine/week from 63 to 65 years. Now in between, this person has used 5 medium glasses of Aperitif per week between 60 and 65 years as well (4th episode).
b) A person might have discontinuous episodes of drinking over life time (e.g., 004-1, episode 1 is from 18 to 29 years. then this person doesn't drink between 30 and 34 years. restarts drinking from 35 years. Such periods of abstinence (30-34 years) has to be deducted from total years of usage .
(The original data was in wide format. I have converted into long format for easier calculation)
I am stuck after this how to calculate alcohol equivalency, convert per day, per week per month to per day, collapsing summary record to each person etc
Any help is appreciated.
I am trying to calculate cumulative measures of alcohol consumption in my l dataset but its getting a bit complicated than smoking measures calculation. I have 9 episodes of drinking habit captured on all participants over their whole life in my data set (Sample data set given below) , with data on
a) Type of beverage they have used (1=wine, 2=beer, 3= hard liq, 4= Aperitif),
b) Start age of consumption in each episode, stop age of consumption in each episode,
c) Unit of alcohol consumed (1= 50 ml, 2= 100ml, 3=250ml, 4=330 ml, 5=725ml),
d) Consumption (how many units) ,
e) Frequency (1= per day, 2=per week, 3= per month).
Finally I want to calculate multiple measures of alcohol from this data. I want Number of Standard drinks of ethanol a) per day, b) per week, c) whole life , all in ml. I want number of grams of ethanol a) per day, b) per week, c) whole life. 1 Standard drink = 17.05 ml of ethanol or 13.5 g of ethanol. There is 0.789 g of ethanol per ml. It will be great if I could get these measures for all a) types of beverages combined b) each beverage separately (wine, beer, hard liq, Aperitif).
Codes that I tried out and Sample dataset with data on 11 participants are given below.
Two the scenarios that can complicate this calculation are:
a) A person might use multiple types of beverages and hence might have overlapping age periods (from and to ages) among any of the 9 episodes (e.g., 001-2, 1st episode is charecterised by this person drinking 2 medium glasses of wine/ month from 20 to 46 yrs of age. 2nd episode is characterised by 3 medium glasses of wine/week between 47 to 62 yrs. 3rd episode, 5 medium glasses of wine/week from 63 to 65 years. Now in between, this person has used 5 medium glasses of Aperitif per week between 60 and 65 years as well (4th episode).
b) A person might have discontinuous episodes of drinking over life time (e.g., 004-1, episode 1 is from 18 to 29 years. then this person doesn't drink between 30 and 34 years. restarts drinking from 35 years. Such periods of abstinence (30-34 years) has to be deducted from total years of usage .
(The original data was in wide format. I have converted into long format for easier calculation)
Code:
/RESHAPING WIDE TO LONG reshape long @_bev_type @_from @_to @_unit @_Howmanyunit @_per, i(id) j(episode) // converting wide data to long mvdecode bev_type from to unit Howmanyunit per, mv (88 888) // converting 88 and 888 to missing values recode bev_type from to unit Howmanyunit per(. = 0) // converting all missing values to 0's assert inlist(bev_type, 1, 2, 3, 4) if !missing(bev_type) gen bev_type label define type 1 "Wine" /// 2 "Beer" /// 3 "Hard liquor" /// 4 "Aperitif" /// label values type type drop _type rename _* * / EXPANDING DATA TO ONE OBSERVATION PER YEAR assert missing(from, to) if unit == 0 drop if unit== 0 // These have no information on duration gen long obs_no = _n expand to - from + 1 by obs_no, sort: gen current_age = from + _n - 1 by obs_no (current_age), sort: assert current_age[_N] == to
Any help is appreciated.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str5 id byte(episode bev_type) int(from to) byte(unit Howmanyunits per) "001-2" 1 1 20 46 2 2 3 "001-2" 2 1 47 62 2 3 2 "001-2" 3 1 63 65 2 5 2 "001-2" 4 4 60 65 2 5 2 "001-2" 5 0 0 0 0 0 0 "001-2" 6 0 0 0 0 0 0 "001-2" 7 0 0 0 0 0 0 "001-2" 8 0 0 0 0 0 0 "001-2" 9 0 0 0 0 0 0 "002-2" 1 0 0 0 0 0 0 "002-2" 2 0 0 0 0 0 0 "002-2" 3 0 0 0 0 0 0 "002-2" 4 0 0 0 0 0 0 "002-2" 5 0 0 0 0 0 0 "002-2" 6 0 0 0 0 0 0 "002-2" 7 0 0 0 0 0 0 "002-2" 8 0 0 0 0 0 0 "002-2" 9 0 0 0 0 0 0 "003-2" 1 2 20 43 4 6 1 "003-2" 2 0 0 0 0 0 0 "003-2" 3 0 0 0 0 0 0 "003-2" 4 0 0 0 0 0 0 "003-2" 5 0 0 0 0 0 0 "003-2" 6 0 0 0 0 0 0 "003-2" 7 0 0 0 0 0 0 "003-2" 8 0 0 0 0 0 0 "003-2" 9 0 0 0 0 0 0 "004-1" 1 1 18 29 2 3 2 "004-1" 2 1 35 72 2 4 2 "004-1" 3 3 40 72 2 2 2 "004-1" 4 0 0 0 0 0 0 "004-1" 5 0 0 0 0 0 0 "004-1" 6 0 0 0 0 0 0 "004-1" 7 0 0 0 0 0 0 "004-1" 8 0 0 0 0 0 0 "004-1" 9 0 0 0 0 0 0 "004-2" 1 1 25 56 2 1 1 "004-2" 2 2 25 56 4 1 2 "004-2" 3 0 0 0 0 0 0 "004-2" 4 0 0 0 0 0 0 "004-2" 5 0 0 0 0 0 0 "004-2" 6 0 0 0 0 0 0 "004-2" 7 0 0 0 0 0 0 "004-2" 8 0 0 0 0 0 0 "004-2" 9 0 0 0 0 0 0 "007-2" 1 1 28 33 2 5 2 "007-2" 2 1 34 50 2 10 2 "007-2" 3 1 51 67 2 15 2 "007-2" 4 1 68 69 2 5 2 "007-2" 5 2 28 58 4 1 1 "007-2" 6 2 59 69 4 2 2 "007-2" 7 0 0 0 0 0 0 "007-2" 8 0 0 0 0 0 0 "007-2" 9 0 0 0 0 0 0 "008-1" 1 2 34 55 4 1 1 "008-1" 2 2 56 59 4 3 1 "008-1" 3 2 20 33 4 15 2 "008-1" 4 1 26 30 2 2 3 "008-1" 5 0 0 0 0 0 0 "008-1" 6 0 0 0 0 0 0 "008-1" 7 0 0 0 0 0 0 "008-1" 8 0 0 0 0 0 0 "008-1" 9 0 0 0 0 0 0 "008-2" 1 0 0 0 0 0 0 "008-2" 2 0 0 0 0 0 0 "008-2" 3 0 0 0 0 0 0 "008-2" 4 0 0 0 0 0 0 "008-2" 5 0 0 0 0 0 0 "008-2" 6 0 0 0 0 0 0 "008-2" 7 0 0 0 0 0 0 "008-2" 8 0 0 0 0 0 0 "008-2" 9 0 0 0 0 0 0 "009-2" 1 1 20 40 2 4 2 "009-2" 2 2 20 49 4 4 2 "009-2" 3 1 41 72 2 1 1 "009-2" 4 3 50 65 1 1 1 "009-2" 5 0 0 0 0 0 0 "009-2" 6 0 0 0 0 0 0 "009-2" 7 0 0 0 0 0 0 "009-2" 8 0 0 0 0 0 0 "009-2" 9 0 0 0 0 0 0 "010-1" 1 2 16 18 4 8 2 "010-1" 2 2 19 41 4 2 2 "010-1" 3 0 0 0 0 0 0 "010-1" 4 0 0 0 0 0 0 "010-1" 5 0 0 0 0 0 0 "010-1" 6 0 0 0 0 0 0 "010-1" 7 0 0 0 0 0 0 "010-1" 8 0 0 0 0 0 0 "010-1" 9 0 0 0 0 0 0 "010-2" 1 1 22 76 3 2 2 "010-2" 2 0 0 0 0 0 0 "010-2" 3 0 0 0 0 0 0 "010-2" 4 0 0 0 0 0 0 "010-2" 5 0 0 0 0 0 0 "010-2" 6 0 0 0 0 0 0 "010-2" 7 0 0 0 0 0 0 "010-2" 8 0 0 0 0 0 0 "010-2" 9 0 0 0 0 0 0 "011-2" 1 2 15 18 4 5 2 "011-2" 2 2 19 50 4 3 1 "011-2" 3 1 21 50 2 2 1 "011-2" 4 0 0 0 0 0 0 "011-2" 5 0 0 0 0 0 0 "011-2" 6 0 0 0 0 0 0 "011-2" 7 0 0 0 0 0 0 "011-2" 8 0 0 0 0 0 0 "011-2" 9 0 0 0 0 0 0 end
Comment