Hello,
I am using panel data from Waves 1 to 3 of the UK Millennium Cohort Study and I have been struggling to deduce the mode of a categorical variable. I have tried researching how to do this online, but it appears STATA does not have a direct mode command? I have made some progress with a work around, however, I am encountering the error message ‘type mismatch’. Does anyone have any suggestions?
The categorical variable I am interested in is ‘frequency of alcohol consumption,’ for which I have three observations per individual i.e. drinking frequency for person X in 2001 (APALDR00), 2004 (BPALDR00), and 2006 (CPALDR00).
My end goal is to generate a new variable equal to the mode of each individual’s frequency of drinking. For example, if individual X drank '1-2 times a month' in 2001, '2-3 times a week' in 2004, and '1-2 times a month' in 2006, I aim for the generated variable to read ‘1-2 times a month’. Alternatively, if they are do not drink, the generated variable should read 'Never'.
Moreover, if there is a missing value, or no mode available, then I would like the variable to read the most frequent entry. For instance, person Y drank 1-2 times a month in 2001, 2-3 times a week in 2004, and missing value in 2006, I would like the variable to read ‘2-3 times a week’. Or person J drank 1-2 times a month in 2001, 'everday' in 2004, and 'less than once a month' in 2006, then the generated variable should read 'less than once a month'
Please find attached the relevant data set, log file, and my Do-File.
Thanks in advance!
I am using panel data from Waves 1 to 3 of the UK Millennium Cohort Study and I have been struggling to deduce the mode of a categorical variable. I have tried researching how to do this online, but it appears STATA does not have a direct mode command? I have made some progress with a work around, however, I am encountering the error message ‘type mismatch’. Does anyone have any suggestions?
The categorical variable I am interested in is ‘frequency of alcohol consumption,’ for which I have three observations per individual i.e. drinking frequency for person X in 2001 (APALDR00), 2004 (BPALDR00), and 2006 (CPALDR00).
My end goal is to generate a new variable equal to the mode of each individual’s frequency of drinking. For example, if individual X drank '1-2 times a month' in 2001, '2-3 times a week' in 2004, and '1-2 times a month' in 2006, I aim for the generated variable to read ‘1-2 times a month’. Alternatively, if they are do not drink, the generated variable should read 'Never'.
Moreover, if there is a missing value, or no mode available, then I would like the variable to read the most frequent entry. For instance, person Y drank 1-2 times a month in 2001, 2-3 times a week in 2004, and missing value in 2006, I would like the variable to read ‘2-3 times a week’. Or person J drank 1-2 times a month in 2001, 'everday' in 2004, and 'less than once a month' in 2006, then the generated variable should read 'less than once a month'
Please find attached the relevant data set, log file, and my Do-File.
Thanks in advance!
Comment